const spy = jest.spyOn(CardResult.prototype, 'expandAnswers');
const wrapper = mount(
<IntlProvider locale="en">
<Provider store={store}>
<CardResult
data={data}
answers={answers}
votedStatus
single
dataCondition="style1"
/>
</Provider>
</IntlProvider>
);
wrapper.find('#cardresultbutton1').simulate('click');
wrapper.update();
expect(spy).toHaveBeenCalled();
i am trying to test a react component method. but i get the following error. please help.
TypeError: Cannot read property '_isMockFunction' of undefined
This error is thrown when the method you are trying to mock is not defined.
This will generate the same error:
const myObject = {}
jest.spyOn(myObject, 'nonexistent')
So your problem is likely in the definition of CardResult
, since CartResult.prototype.expandAnswers
is undefined
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With