@@ -43,41 +43,29 @@ describe("useDimensions", () => {
43
43
const { result } = renderHelper ( ) ;
44
44
expect ( observe ) . not . toHaveBeenCalled ( ) ;
45
45
46
- act ( ( ) => {
47
- result . current . observe ( ) ;
48
- } ) ;
46
+ act ( ( ) => result . current . observe ( ) ) ;
49
47
expect ( observe ) . not . toHaveBeenCalled ( ) ;
50
48
} ) ;
51
49
52
50
it ( "should return workable observe method" , ( ) => {
53
51
const { result } = renderHelper ( ) ;
54
- act ( ( ) => {
55
- result . current . observe ( target ) ;
56
- } ) ;
52
+ act ( ( ) => result . current . observe ( target ) ) ;
57
53
expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
58
54
expect ( observe ) . toHaveBeenCalledTimes ( 1 ) ;
59
55
60
- act ( ( ) => {
61
- result . current . observe ( ) ;
62
- } ) ;
56
+ act ( ( ) => result . current . observe ( ) ) ;
63
57
expect ( observe ) . toHaveBeenCalledTimes ( 2 ) ;
64
58
} ) ;
65
59
66
60
it ( "should not observe repeatedly" , ( ) => {
67
61
const { result } = renderHelper ( ) ;
68
- act ( ( ) => {
69
- result . current . observe ( target ) ;
70
- } ) ;
62
+ act ( ( ) => result . current . observe ( target ) ) ;
71
63
expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
72
64
73
- act ( ( ) => {
74
- result . current . observe ( target ) ;
75
- } ) ;
65
+ act ( ( ) => result . current . observe ( target ) ) ;
76
66
expect ( disconnect ) . toHaveBeenCalledTimes ( 1 ) ;
77
67
78
- act ( ( ) => {
79
- result . current . observe ( document . createElement ( "div" ) ) ;
80
- } ) ;
68
+ act ( ( ) => result . current . observe ( document . createElement ( "div" ) ) ) ;
81
69
expect ( disconnect ) . toHaveBeenCalledTimes ( 2 ) ;
82
70
} ) ;
83
71
@@ -89,10 +77,11 @@ describe("useDimensions", () => {
89
77
90
78
it ( "should return width and height correctly" , ( ) => {
91
79
const { result } = renderHelper ( ) ;
92
- act ( ( ) => {
93
- result . current . observe ( target ) ;
94
- } ) ;
95
80
81
+ expect ( result . current . width ) . toBeNull ( ) ;
82
+ expect ( result . current . height ) . toBeNull ( ) ;
83
+
84
+ act ( ( ) => result . current . observe ( target ) ) ;
96
85
expect ( result . current . width ) . toBe ( 0 ) ;
97
86
expect ( result . current . height ) . toBe ( 0 ) ;
98
87
@@ -110,9 +99,7 @@ describe("useDimensions", () => {
110
99
it ( "should use border-box size" , ( ) => {
111
100
console . warn = jest . fn ( ) ;
112
101
let { result } = renderHelper ( { useBorderBoxSize : true } ) ;
113
- act ( ( ) => {
114
- result . current . observe ( target ) ;
115
- } ) ;
102
+ act ( ( ) => result . current . observe ( target ) ) ;
116
103
const contentBoxSize = { blockSize : 100 , inlineSize : 100 } ;
117
104
act ( ( ) => {
118
105
triggerObserverCb ( { contentBoxSize } ) ;
@@ -125,9 +112,7 @@ describe("useDimensions", () => {
125
112
126
113
console . warn = jest . fn ( ) ;
127
114
result = renderHelper ( { useBorderBoxSize : true } ) . result ;
128
- act ( ( ) => {
129
- result . current . observe ( target ) ;
130
- } ) ;
115
+ act ( ( ) => result . current . observe ( target ) ) ;
131
116
const borderBoxSize = { blockSize : 110 , inlineSize : 110 } ;
132
117
act ( ( ) => triggerObserverCb ( { contentBoxSize, borderBoxSize } ) ) ;
133
118
expect ( console . warn ) . not . toHaveBeenCalledWith ( borderBoxWarn ) ;
@@ -137,24 +122,18 @@ describe("useDimensions", () => {
137
122
138
123
it ( "should return currentBreakpoint correctly" , ( ) => {
139
124
let { result } = renderHelper ( ) ;
140
- act ( ( ) => {
141
- result . current . observe ( target ) ;
142
- } ) ;
125
+ act ( ( ) => result . current . observe ( target ) ) ;
143
126
expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
144
127
145
128
result = renderHelper ( { breakpoints : { T1 : 100 } } ) . result ;
146
- act ( ( ) => {
147
- result . current . observe ( target ) ;
148
- } ) ;
129
+ act ( ( ) => result . current . observe ( target ) ) ;
149
130
act ( ( ) => triggerObserverCb ( { contentRect : { width : 0 } } ) ) ;
150
131
expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
151
132
act ( ( ) => triggerObserverCb ( { contentRect : { width : 99 } } ) ) ;
152
133
expect ( result . current . currentBreakpoint ) . toBe ( "" ) ;
153
134
154
135
result = renderHelper ( { breakpoints : { T0 : 0 , T1 : 100 } } ) . result ;
155
- act ( ( ) => {
156
- result . current . observe ( target ) ;
157
- } ) ;
136
+ act ( ( ) => result . current . observe ( target ) ) ;
158
137
act ( ( ) => triggerObserverCb ( { contentRect : { width : 0 } } ) ) ;
159
138
expect ( result . current . currentBreakpoint ) . toBe ( "T0" ) ;
160
139
act ( ( ) => triggerObserverCb ( { contentRect : { width : 99 } } ) ) ;
@@ -168,9 +147,7 @@ describe("useDimensions", () => {
168
147
169
148
it ( "should return entry correctly" , ( ) => {
170
149
const { result } = renderHelper ( ) ;
171
- act ( ( ) => {
172
- result . current . observe ( target ) ;
173
- } ) ;
150
+ act ( ( ) => result . current . observe ( target ) ) ;
174
151
expect ( result . current . entry ) . toBeUndefined ( ) ;
175
152
176
153
const e = { contentRect : { width : 100 , height : 100 } } ;
@@ -187,9 +164,7 @@ describe("useDimensions", () => {
187
164
it ( "should trigger onResize without breakpoints" , ( ) => {
188
165
const onResize = jest . fn ( ) ;
189
166
const { result } = renderHelper ( { onResize } ) ;
190
- act ( ( ) => {
191
- result . current . observe ( target ) ;
192
- } ) ;
167
+ act ( ( ) => result . current . observe ( target ) ) ;
193
168
const contentRect = { width : 100 , height : 100 } ;
194
169
act ( ( ) => triggerObserverCb ( { contentRect } ) ) ;
195
170
expect ( onResize ) . toHaveBeenCalledWith ( {
@@ -208,9 +183,7 @@ describe("useDimensions", () => {
208
183
breakpoints : { T0 : 0 , T1 : 100 } ,
209
184
onResize,
210
185
} ) ;
211
- act ( ( ) => {
212
- result . current . observe ( target ) ;
213
- } ) ;
186
+ act ( ( ) => result . current . observe ( target ) ) ;
214
187
const contentRect = { width : 50 , height : 100 } ;
215
188
act ( ( ) => {
216
189
triggerObserverCb ( { contentRect } ) ;
@@ -232,9 +205,7 @@ describe("useDimensions", () => {
232
205
breakpoints : { T0 : 100 , T1 : 200 } ,
233
206
updateOnBreakpointChange : true ,
234
207
} ) ;
235
- act ( ( ) => {
236
- result . current . observe ( target ) ;
237
- } ) ;
208
+ act ( ( ) => result . current . observe ( target ) ) ;
238
209
act ( ( ) => triggerObserverCb ( { contentRect : { width : 50 } } ) ) ;
239
210
expect ( result . current . width ) . toBe ( 0 ) ;
240
211
act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
@@ -245,9 +216,7 @@ describe("useDimensions", () => {
245
216
const { result } = renderHelper ( {
246
217
shouldUpdate : ( { width } ) => ( width ?? 0 ) > 300 ,
247
218
} ) ;
248
- act ( ( ) => {
249
- result . current . observe ( target ) ;
250
- } ) ;
219
+ act ( ( ) => result . current . observe ( target ) ) ;
251
220
act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
252
221
expect ( result . current . width ) . toBe ( 0 ) ;
253
222
act ( ( ) => triggerObserverCb ( { contentRect : { width : 400 } } ) ) ;
@@ -260,9 +229,7 @@ describe("useDimensions", () => {
260
229
let { result } = renderHelper ( {
261
230
updateOnBreakpointChange : true ,
262
231
} ) ;
263
- act ( ( ) => {
264
- result . current . observe ( target ) ;
265
- } ) ;
232
+ act ( ( ) => result . current . observe ( target ) ) ;
266
233
act ( ( ) => triggerObserverCb ( { contentRect : { width : 50 } } ) ) ;
267
234
expect ( result . current . width ) . toBe ( 50 ) ;
268
235
@@ -271,9 +238,7 @@ describe("useDimensions", () => {
271
238
updateOnBreakpointChange : true ,
272
239
shouldUpdate : ( { width } ) => ( width ?? 0 ) > 300 ,
273
240
} ) . result ;
274
- act ( ( ) => {
275
- result . current . observe ( target ) ;
276
- } ) ;
241
+ act ( ( ) => result . current . observe ( target ) ) ;
277
242
act ( ( ) => triggerObserverCb ( { contentRect : { width : 100 } } ) ) ;
278
243
expect ( result . current . width ) . toBe ( 0 ) ;
279
244
act ( ( ) => triggerObserverCb ( { contentRect : { width : 400 } } ) ) ;
@@ -309,9 +274,7 @@ describe("useDimensions", () => {
309
274
// @ts -ignore
310
275
delete global . ResizeObserverEntry ;
311
276
const { result } = renderHelper ( { polyfill : mockResizeObserver } ) ;
312
- act ( ( ) => {
313
- result . current . observe ( target ) ;
314
- } ) ;
277
+ act ( ( ) => result . current . observe ( target ) ) ;
315
278
expect ( observe ) . toHaveBeenCalledTimes ( 1 ) ;
316
279
} ) ;
317
280
} ) ;
0 commit comments