i building basic blogging app react. using jasmine , karma run front end tests. got first test , running , passes in chrome (chromium) , firefox, when runs in phantomjs following error:
phantomjs 1.9.8 (linux 0.0.0) error typeerror: 'undefined' not function (evaluating 'reactelementvalidator.createelement.bind( null, type )') @ /home/michael/repository/short-stories/test/karma_tests/story_test.js:1742 my test file looks this:
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 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 deleting node_modules, , npm cache clear , npm install, didn't fix it. i'm not sure how tests pass in firefox , chrome, not in phantomjs. can see full project here: https://github.com/mrbgit/short-stories . let me know if there's more info help. appreciated. thanks!
phantomjs uses rather old version of qt-webkit not provide function.prototype.bind. problem lot of libraries, polyfill npm module called 'phantomjs-polyfill' available.
if you'd rather not use npm modules (if you're testing browser site hasn't been bundled browserify/webpack), following polyfill bind provided on mdn page , can attach yourself:
if (!function.prototype.bind) { function.prototype.bind = function(othis) { if (typeof !== 'function') { // closest thing possible ecmascript 5 // internal iscallable function throw new typeerror('function.prototype.bind - trying bound not callable'); } var aargs = array.prototype.slice.call(arguments, 1), ftobind = this, fnop = function() {}, fbound = function() { return ftobind.apply(this instanceof fnop ? : othis, aargs.concat(array.prototype.slice.call(arguments))); }; fnop.prototype = this.prototype; fbound.prototype = new fnop(); return fbound; }; }
Comments
Post a Comment