【发布时间】:2015-09-29 15:09:31
【问题描述】:
我正在使用 React 构建一个基本的博客应用程序。我正在使用 Jasmine 和 Karma 来运行我的前端测试。我的第一个测试启动并运行,它在 Chrome (Chromium) 和 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。让我知道是否有更多信息可以提供帮助。任何帮助表示赞赏。谢谢!
【问题讨论】:
标签: javascript unit-testing jasmine karma-jasmine