score:1

Accepted answer

the problem is what you expected is not the mocked method. you should expect the mocked method like this:

expect(store.handleloginsubmit).tohavebeencalledtimes(0)

and similar to other expect.

in the end of your test case, you should restore the mocked method by calling .mockrestore():

store.handleloginsubmit.mockrestore()

if after this, you still get issue with async call, here's my suggestion that makes your tests be more ...unit test: you should separate the test into 2 test cases, one to test if store.handleloginsubmit is called after form is submitted, and the other one is to test what inside store.handleloginsubmit,

test('.handleloginsubmit() called when form is submitted', () => {
  jest.spyon(store, 'handleloginsubmit').mockimplementation(() => {})
  const wrapper = shallow(<login store={store} />);
  wrapper.find('form').simulate('submit');
  expect(store.handleloginsubmit).tobecalled()
  store.handleloginsubmit.mockrestore()
})

test('.handleloginsubmit()', async () => {
  jest.spyon(service, 'validateuser')
    .mockimplementation(() => promise.resolve(true))
  await store.handleloginsubmit({preventdefault: () => {}})
  expect(service.validateuser).tobecalled()
  service.validateuser.mockrestore()
})

Related Query

More Query from same tag