Skip to content

Commit

Permalink
test: fix test failure in react strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fpsqdb committed Jan 15, 2025
1 parent c69bf15 commit 6b7634e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tests/resetStore.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe("resetStore", () => {
it("reset specific store should not cause other store re-render.", async () => {
const { useStore, createProvider, useProvider } = await act(async () => await import("houp"));
const user = userEvent.setup();
const reactStrictMode = Boolean(process.env.TEST_STRICT_MODE);
function hook() {
return useState(0);
}
Expand Down Expand Up @@ -120,28 +121,28 @@ describe("resetStore", () => {
<Component2 />
</Provider>
));
expect(render1).toBeCalledTimes(1);
expect(render2).toBeCalledTimes(1);
expect(render1).toBeCalledTimes(reactStrictMode ? 2 : 1);
expect(render2).toBeCalledTimes(reactStrictMode ? 2 : 1);
await screen.findByText("value:0");
await screen.findByText("value-2:0");
await user.click(screen.getByTestId("button"));
expect(render1).toBeCalledTimes(2);
expect(render2).toBeCalledTimes(1);
expect(render1).toBeCalledTimes(reactStrictMode ? 4 : 2);
expect(render2).toBeCalledTimes(reactStrictMode ? 2 : 1);
await screen.findByText("value:1");
await screen.findByText("value-2:0");
await user.click(screen.getByTestId("button2"));
expect(render1).toBeCalledTimes(3);
expect(render2).toBeCalledTimes(1);
expect(render1).toBeCalledTimes(reactStrictMode ? 6 : 3);
expect(render2).toBeCalledTimes(reactStrictMode ? 2 : 1);
await screen.findByText("value:0");
await screen.findByText("value-2:0");
await user.click(screen.getByTestId("button-2"));
expect(render1).toBeCalledTimes(3);
expect(render2).toBeCalledTimes(2);
expect(render1).toBeCalledTimes(reactStrictMode ? 6 : 3);
expect(render2).toBeCalledTimes(reactStrictMode ? 4 : 2);
await screen.findByText("value:0");
await screen.findByText("value-2:1");
await user.click(screen.getByTestId("button2-2"));
expect(render1).toBeCalledTimes(3);
expect(render2).toBeCalledTimes(3);
expect(render1).toBeCalledTimes(reactStrictMode ? 6 : 3);
expect(render2).toBeCalledTimes(reactStrictMode ? 6 : 3);
await screen.findByText("value:0");
await screen.findByText("value-2:0");
})
Expand Down

0 comments on commit 6b7634e

Please sign in to comment.