Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use invoke with async state #2527

Open
chanelnumberseven opened this issue Jun 24, 2021 · 0 comments
Open

how to use invoke with async state #2527

chanelnumberseven opened this issue Jun 24, 2021 · 0 comments

Comments

@chanelnumberseven
Copy link

chanelnumberseven commented Jun 24, 2021

index.test.tsx:

 it('delete', async () => {
    const onDel = jest.fn();
    const wrapper = mount(
      <Component
        onDel={onDel}
      />,
    );

    const modal = wrapper.find(Modal);

    await modal.invoke('onOk')().then(()=>{
      expect(onDel.mock.calls).toHaveLength(1);
    });
  });
});

the onOk prop look like:

onOk={async () => {
  await form.validateFields(['target']).then(() => {
    onDel();
    setVisible.setFalse();
  });
}}

get warning:
E2A965DD-6051-41EB-B648-8013D8E396B2

it work well when onOk look like(just move the state change outside the promise) :

onOk={async () => {
  setVisible.setFalse();
  await form.validateFields(['target']).then(() => {
    onDel();
  });
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant