Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I Can't do work. jasmineReact.spyOnClass(); #10

Open
ericzwong opened this issue Oct 30, 2015 · 4 comments
Open

I Can't do work. jasmineReact.spyOnClass(); #10

ericzwong opened this issue Oct 30, 2015 · 4 comments

Comments

@ericzwong
Copy link

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 (

{ name }

);
}
};

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');

});
});

@xhawk
Copy link

xhawk commented Dec 29, 2015

I'm getting the same error with ES6/Babel.

@afraser
Copy link

afraser commented Jan 7, 2016

ditto.

@jolyonruss
Copy link

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.

@icd2k3
Copy link

icd2k3 commented Mar 22, 2016

Same problem here, any work-arounds? I'm trying to use this to test methods like componentDidMount or other custom internal component functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants