last day (15 days later) » 

2:56 AM
1
A: Jest TypeError: e.preventDefault is not a function

RikinTry passing mockEvent object as second argument. component.find('form').simulate('submit', { preventDefault });

 
the solution in your comment worked. It passes now. But this edit gives me an error.
 
Right, this is the same code, twisted a bit to be more expressive and extendable in case you need more properties on the event Mock.
 
what about component.setState({ currentTask:"test-task", tasks:[...items, 'test-task'] }) ?
please edit it back to the way it was, so i can mark this as an answer, im getting an error now.
 
Hmm interesting, I would have to try out how it differs.
 
this is the error i got, if your curious Expected mock function to have been called, but it was not called.
this(as in your current edit) passes, however would you write this handleSubmit test differently ?
 
2:56 AM
Ah you just need to store the reference of the jest.fn() on which you can do expect
 
can you make an edit, so i can have a better idea. thanks.
 
so it would be like this
const preventDefault = jest.fn();
const mockEvent = { preventDefault }
and then you would pass mockEvent object to the simulate and still be able to test preventDefault spy function
hope it makes sense
const preventDefault = jest.fn();
const mockEvent = { preventDefault /*possibly add more properties if need to*/ }

component.find('form').simulate('submit', mockEvent);
 
3:13 AM
sorry for the wait
was in the shower
let me give this a shot
im just going to stick with the original solution thanks though.
 

last day (15 days later) »