Skip to content

Commit b12574c

Browse files
Issue #45 Console warnings in use-window hook tests
Fix use-window.test.tsx to use act
2 parents b6bba47 + 0a76eba commit b12574c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/hooks/use-window.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { renderHook } from "@testing-library/react-hooks";
1+
import { renderHook, act } from "@testing-library/react-hooks";
22
import { useWindow } from "./use-window";
33

44
const DEFAULT_WIDTH: number = 1024;
55
const DEFAULT_HEIGHT: number = 768;
66

77
describe("useWindow", () => {
88
beforeEach(() => {
9-
window.resizeTo(DEFAULT_WIDTH, DEFAULT_HEIGHT);
9+
act(() => {
10+
window.resizeTo(DEFAULT_WIDTH, DEFAULT_HEIGHT);
11+
});
1012
});
1113

1214
test("returns width and height of window", async () => {
@@ -25,7 +27,9 @@ describe("useWindow", () => {
2527
const windowHeight = DEFAULT_HEIGHT + 1;
2628

2729
// Act
28-
window.resizeTo(windowWidth, windowHeight);
30+
act(() => {
31+
window.resizeTo(windowWidth, windowHeight);
32+
});
2933

3034
// Assert
3135
expect(result.current.width).toBe(windowWidth);

0 commit comments

Comments
 (0)