File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { renderHook } from "@testing-library/react-hooks" ;
1+ import { renderHook , act } from "@testing-library/react-hooks" ;
22import { useWindow } from "./use-window" ;
33
44const DEFAULT_WIDTH : number = 1024 ;
55const DEFAULT_HEIGHT : number = 768 ;
66
77describe ( "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 ) ;
You can’t perform that action at this time.
0 commit comments