reactjs - How to unit test addTodo in redux app? -


i trying example :

https://github.com/reactjs/redux/tree/master/examples/todomvc

based in solution have created unit test looks this:

it('should call addtodo if length of text greater 0', () => {      const props = {       addtodo: jest.fn()     }      let cb = shallow(<header {...props} />)      expect(props.addtodo).not.tobecalled()      cb.find('todotextinput').simulate("onsave",{text:"fsdhsd"});      //error starts here:     expect(props.addtodo).tobecalled()     }); 

the result of 1 : fail src/components/newheadertest.spec.js ●

header enzyme style › should call addtodo if length of text greater 0      expect(jest.fn()).tobecalled()      expected mock function have been called.      @ object.it (src/components/newheadertest.spec.js:46:27) 

this part of component:

handlesave = text => {     console.log('handlesave');     if (text.length > 0) {       this.props.addtodo(text);     }   }    render = () => {     return (       <header classname="header">         <todotextinput onsave={this.handlesave}>         </todotextinput>       </header>)   } 

how can fix unittest or how pass in argument simulate statement: cb.find('todotextinput').simulate("onsave",{text:"fsdhsd"});


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -