-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
import React from "preact/compat";
import { act, renderHook } from "@testing-library/preact-hooks";
// works:
// import React from "react";
// import { act, renderHook } from "@testing-library/react-hooks";
function useTest() {
let [state, setState] = React.useState(1);
return {
value: state,
async increment() {
await new Promise((res) => setTimeout(res, 100));
setState((i) => i + 1);
},
};
}
test("test", async () => {
let { result, waitForNextUpdate } = renderHook(() => useTest());
expect(result.current.value).toBe(1);
await act(async () => {
result.current.increment();
await waitForNextUpdate();
});
expect(result.current.value).toBe(2);
});Without await waitForNextUpdate(), the second assertion fails.
With that call, Jest times out (this works as expected when using React).
vilchesalves
Metadata
Metadata
Assignees
Labels
No labels