reactjs - Attempting to test a React component with jasmine-react -


this question similar one of solutions question.

i'm using example similar real problem nicely distilled.

the following test produces result:

warning: comp.type deprecated. use comp directly access class.   error: expected spy, 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 i'm doing wrong?

jasminereact's syntax method expectations different way you're using it. try this:

expect(jasminereact.classprototype(comp).plop).tohavebeencalled(); 

additionally, if you're running expectation against state, need use instance render returns, rather class:

var comp = jasminereact.render(<comp />);  expect(comp.state.something).tobe('else'); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -