我正在用React构建一个基本的博客应用程序。我正在使用Jasmine和Karma来运行我的前端测试。我得到了我的第一次测试启动和运行,并将其传递在Chrome(铬)和Firefox,但是当它运行在PhantomJS我得到以下错误:茉莉花测试通过Chrome和Firefox,但失败PhantomJS
PhantomJS 1.9.8 (Linux 0.0.0) ERROR
TypeError: 'undefined' is not a function (evaluating 'ReactElementValidator.createElement.bind(
null,
type
)')
at /home/michael/repository/short-stories/test/karma_tests/story_test.js:1742
我的测试文件看起来像这样:
var React = require('react/addons');
var Story = require('../../app/js/components/story.jsx');
var TestUtils = React.addons.TestUtils;
var testUtilsAdditions = require('react-testutils-additions');
describe('Story component', function() {
var component;
beforeEach(function() {
component = TestUtils.renderIntoDocument(React.createElement('story'));
component.props.storyTitle = 'front end test title';
component.props.author = 'front end author';
component.props.storyText = 'front end story text';
});
it('should display a story', function() {
expect(component.props).toBeDefined();
expect(component.props.storyTitle).toBeDefined();
expect(component.props.storyTitle).toBe('front end test title');
expect(component.props.author).toBe('front end author');
expect(component.props.storyText).toBe('front end story text')
});
});
我尝试删除我的node_modules,并且npm缓存清除和npm安装,但是它没有修复它。我不确定我的测试如何在Firefox和Chrome中传递,但不在PhantomJS中传递。你可以在这里看到完整的项目:https://github.com/mrbgit/short-stories。如果有更多信息可以帮助,请告诉我。任何帮助表示赞赏。谢谢!
谢谢ssube,修复它! – CascadiaJS