简体   繁体   中英

Jest spyOn handleSubmit() method does not exist

My test case goes like this:

describe('Personal Profile', () => {
  
  it('renders', () => {
    
    const wrapper = mount(
      <PersonalProfile store={store}/>
    ); 
    const spy = jest.spyOn(wrapper.instance(), 'handleChangetype')
    wrapper.update();
    wrapper.find(Typeahead).at(2).simulate('change');
    console.log(wrapper.find(Typeahead).at(2).simulate('change').debug())
    
    expect(spy).toHaveBeenCalled();
  });
});

在此处输入图片说明

I am getting the above error while running the test case.

In my js file, I have not used arrow functions and bound the method in the constructor though I m having this error.

can anybody help?

I am able to figure it out. the problem was that I used redux store and it was trying to find the method in the connect component. So what I needed to do is to call .first().shallow() on my wrapper to get the component I want.

const wrapper = shallow(
      
        <PersonalProfile store={store}/>
      
    ).first().shallow().first().shallow();

Did this as I have two HOCs so get the desired component I have to shallow the first component of previous return twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM