I am building a basic blogging application with React. I use Jasmine and Karma to run my front end tests. I got my first test and it works, and it runs in Chrome (Chromium) and Firefox, but when it runs in PhantomJS, I get the following error:
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
My test file is as follows:
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') }); });
I tried to remove my node_modules and the npm cache cleaned and installed npm, but it did not fix it. I'm not sure how my tests can pass in Firefox and Chrome, but not in PhantomJS. You can see the full project here: https://github.com/mrbgit/short-stories . Let me know if there is any information that could help. Any help is appreciated. Thanks!
source share