jasmine-react
jasmine-react copied to clipboard
I Can't do work. jasmineReact.spyOnClass();
I get this error: "A component constructor could not be found for this class. Are you sure you passed in a the component definition for a React component? thrown"
and i use karma + babel
var React = require('react'); var TestUtils = require('react-addons-test-utils'); var ReactDOM = require('react-dom'); var rewire = require('rewire'); var jasmineReact = require('jasmine-react-helpers'); // var HelloRandom = require('../components/helloworld');
class HelloRandom extends React.Component { getRandomAuthor() { let names = [ 'aliceyang', 'wangzhe', 'bill', 'cook' ]; return names[Math.floor(Math.random() * names.length)]; } render() { let name = this.getRandomAuthor(); return (
describe("Hello Random", function () { it("should spy on a function of react class", function () { jasmineReact.spyOnClass(HelloRandom, 'getRandomAuthor').andReturn('wangzhe');
let HelloRandomComponent = TestUtils.renderIntoDocument(<HelloRandom/>);
expect(ReactDOM.findDOMNode(HelloRandomComponent).innerHTML).toEqual('wangzhe');
}); });
I'm getting the same error with ES6/Babel.
ditto.
It looks like this isn't compatible with React 0.14.X
I resolved by using TestUtils.renderIntoDocument
and ReactDOM.findDOMNode
to get the React component and DOM element.
Same problem here, any work-arounds? I'm trying to use this to test methods like componentDidMount or other custom internal component functions.