@@ -43,41 +43,29 @@ describe("useDimensions", () => {
4343 const { result } = renderHelper ( ) ;
4444 expect ( observe ) . not . toHaveBeenCalled ( ) ;
4545
46- act ( ( ) => {
47- result . current . observe ( ) ;
48- } ) ;
46+ act ( ( ) => result . current . observe ( ) ) ;
4947 expect ( observe ) . not . toHaveBeenCalled ( ) ;
5048 } ) ;
5149
5250 it ( "should return workable observe method" , ( ) => {
5351 const { result } = renderHelper ( ) ;
54- act ( ( ) => {
55- result . current . observe ( target ) ;
56- } ) ;
52+ act ( ( ) => result . current . observe ( target ) ) ;
5753 expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
5854 expect ( observe ) . toHaveBeenCalledTimes ( 1 ) ;
5955
60- act ( ( ) => {
61- result . current . observe ( ) ;
62- } ) ;
56+ act ( ( ) => result . current . observe ( ) ) ;
6357 expect ( observe ) . toHaveBeenCalledTimes ( 2 ) ;
6458 } ) ;
6559
6660 it ( "should not observe repeatedly" , ( ) => {
6761 const { result } = renderHelper ( ) ;
68- act ( ( ) => {
69- result . current . observe ( target ) ;
70- } ) ;
62+ act ( ( ) => result . current . observe ( target ) ) ;
7163 expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
7264
73- act ( ( ) => {
74- result . current . observe ( target ) ;
75- } ) ;
65+ act ( ( ) => result . current . observe ( target ) ) ;
7666 expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
7767
78- act ( ( ) => {
79- result . current . observe ( document . createElement ( "div" ) ) ;
80- } ) ;
68+ act ( ( ) => result . current . observe ( document . createElement ( "div" ) ) ) ;
8169 expect ( disconnect ) . toHaveBeenCalledTimes ( 2 ) ;
8270 } ) ;
8371
@@ -89,10 +77,11 @@ describe("useDimensions", () => {
8977
9078 it ( "should return width and height correctly" , ( ) => {
9179 const { result } = renderHelper ( ) ;
92- act ( ( ) => {
93- result . current . observe ( target ) ;
94- } ) ;
9580
81+ expect ( result . current . width ) . toBeNull ( ) ;
82+ expect ( result . current . height ) . toBeNull ( ) ;
83+
84+ act ( ( ) => result . current . observe ( target ) ) ;
9685 expect ( result . current . width ) . toBe ( 0 ) ;
9786 expect ( result . current . height ) . toBe ( 0 ) ;
9887
@@ -110,9 +99,7 @@ describe("useDimensions", () => {
11099 it ( "should use border-box size" , ( ) => {
111100 console . warn = jest . fn ( ) ;
112101 let { result } = renderHelper ( { useBorderBoxSize : true } ) ;
113- act ( ( ) => {
114- result . current . observe ( target ) ;
115- } ) ;
102+ act ( ( ) => result . current . observe ( target ) ) ;
116103 const contentBoxSize = { blockSize : 100 , inlineSize : 100 } ;
117104 act ( ( ) => {
118105 triggerObserverCb ( { contentBoxSize } ) ;
@@ -125,9 +112,7 @@ describe("useDimensions", () => {
125112
126113 console . warn = jest . fn ( ) ;
127114 result = renderHelper ( { useBorderBoxSize : true } ) . result ;
128- act ( ( ) => {
129- result . current . observe ( target ) ;
130- } ) ;
115+ act ( ( ) => result . current . observe ( target ) ) ;
131116 const borderBoxSize = { blockSize : 110 , inlineSize : 110 } ;
132117 act ( ( ) => triggerObserverCb ( { contentBoxSize, borderBoxSize } ) ) ;
133118 expect ( console . warn ) . not . toHaveBeenCalledWith ( borderBoxWarn ) ;
@@ -137,24 +122,18 @@ describe("useDimensions", () => {
137122
138123 it ( "should return currentBreakpoint correctly" , ( ) => {
139124 let { result } = renderHelper ( ) ;
140- act ( ( ) => {
141- result . current . observe ( target ) ;
142- } ) ;
125+ act ( ( ) => result . current . observe ( target ) ) ;
143126 expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
144127
145128 result = renderHelper ( { breakpoints : { T1 : 100 } } ) . result ;
146- act ( ( ) => {
147- result . current . observe ( target ) ;
148- } ) ;
129+ act ( ( ) => result . current . observe ( target ) ) ;
149130 act ( ( ) => triggerObserverCb ( { contentRect : { width : 0 } } ) ) ;
150131 expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
151132 act ( ( ) => triggerObserverCb ( { contentRect : { width : 99 } } ) ) ;
152133 expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
153134
154135 result = renderHelper ( { breakpoints : { T0 : 0 , T1 : 100 } } ) . result ;
155- act ( ( ) => {
156- result . current . observe ( target ) ;
157- } ) ;
136+ act ( ( ) => result . current . observe ( target ) ) ;
158137 act ( ( ) => triggerObserverCb ( { contentRect : { width : 0 } } ) ) ;
159138 expect ( result . current . currentBreakpoint ) . toBe ( "T0" ) ;
160139 act ( ( ) => triggerObserverCb ( { contentRect : { width : 99 } } ) ) ;
@@ -168,9 +147,7 @@ describe("useDimensions", () => {
168147
169148 it ( "should return entry correctly" , ( ) => {
170149 const { result } = renderHelper ( ) ;
171- act ( ( ) => {
172- result . current . observe ( target ) ;
173- } ) ;
150+ act ( ( ) => result . current . observe ( target ) ) ;
174151 expect ( result . current . entry ) . toBeUndefined ( ) ;
175152
176153 const e = { contentRect : { width : 100 , height : 100 } } ;
@@ -187,9 +164,7 @@ describe("useDimensions", () => {
187164 it ( "should trigger onResize without breakpoints" , ( ) => {
188165 const onResize = jest . fn ( ) ;
189166 const { result } = renderHelper ( { onResize } ) ;
190- act ( ( ) => {
191- result . current . observe ( target ) ;
192- } ) ;
167+ act ( ( ) => result . current . observe ( target ) ) ;
193168 const contentRect = { width : 100 , height : 100 } ;
194169 act ( ( ) => triggerObserverCb ( { contentRect } ) ) ;
195170 expect ( onResize ) . toHaveBeenCalledWith ( {
@@ -208,9 +183,7 @@ describe("useDimensions", () => {
208183 breakpoints : { T0 : 0 , T1 : 100 } ,
209184 onResize,
210185 } ) ;
211- act ( ( ) => {
212- result . current . observe ( target ) ;
213- } ) ;
186+ act ( ( ) => result . current . observe ( target ) ) ;
214187 const contentRect = { width : 50 , height : 100 } ;
215188 act ( ( ) => {
216189 triggerObserverCb ( { contentRect } ) ;
@@ -232,9 +205,7 @@ describe("useDimensions", () => {
232205 breakpoints : { T0 : 100 , T1 : 200 } ,
233206 updateOnBreakpointChange : true ,
234207 } ) ;
235- act ( ( ) => {
236- result . current . observe ( target ) ;
237- } ) ;
208+ act ( ( ) => result . current . observe ( target ) ) ;
238209 act ( ( ) => triggerObserverCb ( { contentRect : { width : 50 } } ) ) ;
239210 expect ( result . current . width ) . toBe ( 0 ) ;
240211 act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
@@ -245,9 +216,7 @@ describe("useDimensions", () => {
245216 const { result } = renderHelper ( {
246217 shouldUpdate : ( { width } ) => ( width ?? 0 ) > 300 ,
247218 } ) ;
248- act ( ( ) => {
249- result . current . observe ( target ) ;
250- } ) ;
219+ act ( ( ) => result . current . observe ( target ) ) ;
251220 act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
252221 expect ( result . current . width ) . toBe ( 0 ) ;
253222 act ( ( ) => triggerObserverCb ( { contentRect : { width : 400 } } ) ) ;
@@ -260,9 +229,7 @@ describe("useDimensions", () => {
260229 let { result } = renderHelper ( {
261230 updateOnBreakpointChange : true ,
262231 } ) ;
263- act ( ( ) => {
264- result . current . observe ( target ) ;
265- } ) ;
232+ act ( ( ) => result . current . observe ( target ) ) ;
266233 act ( ( ) => triggerObserverCb ( { contentRect : { width : 50 } } ) ) ;
267234 expect ( result . current . width ) . toBe ( 50 ) ;
268235
@@ -271,9 +238,7 @@ describe("useDimensions", () => {
271238 updateOnBreakpointChange : true ,
272239 shouldUpdate : ( { width } ) => ( width ?? 0 ) > 300 ,
273240 } ) . result ;
274- act ( ( ) => {
275- result . current . observe ( target ) ;
276- } ) ;
241+ act ( ( ) => result . current . observe ( target ) ) ;
277242 act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
278243 expect ( result . current . width ) . toBe ( 0 ) ;
279244 act ( ( ) => triggerObserverCb ( { contentRect : { width : 400 } } ) ) ;
@@ -309,9 +274,7 @@ describe("useDimensions", () => {
309274 // @ts -ignore
310275 delete global . ResizeObserverEntry ;
311276 const { result } = renderHelper ( { polyfill : mockResizeObserver } ) ;
312- act ( ( ) => {
313- result . current . observe ( target ) ;
314- } ) ;
277+ act ( ( ) => result . current . observe ( target ) ) ;
315278 expect ( observe ) . toHaveBeenCalledTimes ( 1 ) ;
316279 } ) ;
317280} ) ;
0 commit comments