This question is very similar to one of the solutions to this question.
I'm using this as my example as its similar to my real problem but nicely distilled.
The following test produces this result:
Warning: Comp.type is deprecated. Use Comp directly to access the class.
Error: Expected a spy, but got undefined.
The test:
it("should call plop method on render", function(){
var Comp = React.createClass({
displayName: "Comp",
plop: function() {
console.log("plop");
},
render: function() {
this.plop();
return (<div></div>);
}
});
//spy on method
jasmineReact.spyOnClass(Comp, "plop");
jasmineReact.render(<Comp />);
expect(Comp.plop).toHaveBeenCalled();
})
Any idea what I'm doing wrong?
JasmineReact's syntax for method expectations is different to the way you're using it. Try this:
Additionally, if you're running an expectation against something like state, you need to use the instance that
render
returns, rather than the class: