cossack910 / ReactJest

React Testing Library + JEST
0 stars 0 forks source link

React testing library waitFor #19

Open cossack910 opened 11 months ago

cossack910 commented 11 months ago

非同期処理でチェックする必要があるテストで使用する。タイムアウトに到達するまでCallbackを何度も実行する。 ※awaitは必ず併用すること。

it("プラスボタン3回クリック", async () => {
    render(
      <Provider store={store}>
        <Redux />
      </Provider>
    );
    await userEvent.click(screen.getByText("+"));
    await userEvent.click(screen.getByText("+"));
    await userEvent.click(screen.getByText("+"));
    await waitFor(() => {
      expect(screen.getByTestId("count-value")).toHaveTextContent("3");
    });
  });