Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'_isMockFunction' of undefined

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

like image 906
oav Avatar asked Sep 20 '17 13:09

oav


1 Answers

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.

like image 140
halbgut Avatar answered Nov 09 '22 08:11

halbgut