@wordpress/compose 5.19.0 → 5.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +8 -8
- package/src/hooks/use-merge-refs/test/index.js +36 -63
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.20.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/mousetrap": "^1.6.8",
|
|
34
|
-
"@wordpress/deprecated": "^3.
|
|
35
|
-
"@wordpress/dom": "^3.
|
|
36
|
-
"@wordpress/element": "^4.
|
|
37
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
38
|
-
"@wordpress/keycodes": "^3.
|
|
39
|
-
"@wordpress/priority-queue": "^2.
|
|
34
|
+
"@wordpress/deprecated": "^3.22.0",
|
|
35
|
+
"@wordpress/dom": "^3.22.0",
|
|
36
|
+
"@wordpress/element": "^4.20.0",
|
|
37
|
+
"@wordpress/is-shallow-equal": "^4.22.0",
|
|
38
|
+
"@wordpress/keycodes": "^3.22.0",
|
|
39
|
+
"@wordpress/priority-queue": "^2.22.0",
|
|
40
40
|
"change-case": "^4.1.2",
|
|
41
41
|
"clipboard": "^2.0.8",
|
|
42
42
|
"mousetrap": "^1.6.5",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "7ac04f446242452d3cb24372f9ca58f0cae97715"
|
|
52
52
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -38,7 +38,7 @@ describe( 'useMergeRefs', () => {
|
|
|
38
38
|
|
|
39
39
|
function MergedRefs( {
|
|
40
40
|
count,
|
|
41
|
-
tagName: TagName = '
|
|
41
|
+
tagName: TagName = 'ul',
|
|
42
42
|
disable1,
|
|
43
43
|
disable2,
|
|
44
44
|
unused,
|
|
@@ -71,31 +71,22 @@ describe( 'useMergeRefs', () => {
|
|
|
71
71
|
return <TagName ref={ mergedRefs } />;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
beforeEach( () => {
|
|
75
|
-
const rootElement = document.createElement( 'div' );
|
|
76
|
-
rootElement.id = 'root';
|
|
77
|
-
document.body.appendChild( rootElement );
|
|
78
|
-
} );
|
|
79
|
-
|
|
80
74
|
afterEach( () => {
|
|
81
|
-
// Reset all history
|
|
75
|
+
// Reset all history.
|
|
82
76
|
renderCallback.history = [];
|
|
83
|
-
document.body.innerHTML = '';
|
|
84
77
|
} );
|
|
85
78
|
|
|
86
79
|
it( 'should work', () => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
ReactDOM.render( <MergedRefs />, rootElement );
|
|
80
|
+
const { rerender, unmount } = render( <MergedRefs /> );
|
|
90
81
|
|
|
91
|
-
const originalElement =
|
|
82
|
+
const originalElement = screen.getByRole( 'list' );
|
|
92
83
|
|
|
93
84
|
// Render 1: both initial callback functions should be called with node.
|
|
94
85
|
expect( renderCallback.history ).toEqual( [
|
|
95
86
|
[ [ originalElement ], [ originalElement ] ],
|
|
96
87
|
] );
|
|
97
88
|
|
|
98
|
-
|
|
89
|
+
rerender( <MergedRefs /> );
|
|
99
90
|
|
|
100
91
|
// Render 2: the new callback functions should not be called! There has
|
|
101
92
|
// been no dependency change.
|
|
@@ -104,7 +95,7 @@ describe( 'useMergeRefs', () => {
|
|
|
104
95
|
[ [], [] ],
|
|
105
96
|
] );
|
|
106
97
|
|
|
107
|
-
|
|
98
|
+
unmount();
|
|
108
99
|
|
|
109
100
|
// Unmount: the initial callback functions should receive null.
|
|
110
101
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -117,15 +108,13 @@ describe( 'useMergeRefs', () => {
|
|
|
117
108
|
} );
|
|
118
109
|
|
|
119
110
|
it( 'should work for node change', () => {
|
|
120
|
-
const
|
|
111
|
+
const { rerender, unmount } = render( <MergedRefs /> );
|
|
121
112
|
|
|
122
|
-
|
|
113
|
+
const originalElement = screen.getByRole( 'list' );
|
|
123
114
|
|
|
124
|
-
|
|
115
|
+
rerender( <MergedRefs tagName="button" /> );
|
|
125
116
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const newElement = rootElement.firstElementChild;
|
|
117
|
+
const newElement = screen.getByRole( 'button' );
|
|
129
118
|
|
|
130
119
|
// After a render with the original element and a second render with the
|
|
131
120
|
// new element, expect the initial callback functions to be called with
|
|
@@ -140,7 +129,7 @@ describe( 'useMergeRefs', () => {
|
|
|
140
129
|
[ [], [] ],
|
|
141
130
|
] );
|
|
142
131
|
|
|
143
|
-
|
|
132
|
+
unmount();
|
|
144
133
|
|
|
145
134
|
// Unmount: the initial callback functions should receive null.
|
|
146
135
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -153,17 +142,15 @@ describe( 'useMergeRefs', () => {
|
|
|
153
142
|
} );
|
|
154
143
|
|
|
155
144
|
it( 'should work with dependencies', () => {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
ReactDOM.render( <MergedRefs count={ 1 } />, rootElement );
|
|
145
|
+
const { rerender, unmount } = render( <MergedRefs count={ 1 } /> );
|
|
159
146
|
|
|
160
|
-
const originalElement =
|
|
147
|
+
const originalElement = screen.getByRole( 'list' );
|
|
161
148
|
|
|
162
149
|
expect( renderCallback.history ).toEqual( [
|
|
163
150
|
[ [ originalElement ], [ originalElement ] ],
|
|
164
151
|
] );
|
|
165
152
|
|
|
166
|
-
|
|
153
|
+
rerender( <MergedRefs count={ 2 } /> );
|
|
167
154
|
|
|
168
155
|
// After a second render with a dependency change, expect the inital
|
|
169
156
|
// callback function to be called with null and the new callback
|
|
@@ -174,7 +161,7 @@ describe( 'useMergeRefs', () => {
|
|
|
174
161
|
[ [], [ originalElement ] ],
|
|
175
162
|
] );
|
|
176
163
|
|
|
177
|
-
|
|
164
|
+
unmount();
|
|
178
165
|
|
|
179
166
|
// Unmount: current callback functions should be called with null.
|
|
180
167
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -187,22 +174,17 @@ describe( 'useMergeRefs', () => {
|
|
|
187
174
|
} );
|
|
188
175
|
|
|
189
176
|
it( 'should simultaneously update node and dependencies', () => {
|
|
190
|
-
const
|
|
177
|
+
const { rerender, unmount } = render( <MergedRefs count={ 1 } /> );
|
|
191
178
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const originalElement = rootElement.firstElementChild;
|
|
179
|
+
const originalElement = screen.getByRole( 'list' );
|
|
195
180
|
|
|
196
181
|
expect( renderCallback.history ).toEqual( [
|
|
197
182
|
[ [ originalElement ], [ originalElement ] ],
|
|
198
183
|
] );
|
|
199
184
|
|
|
200
|
-
|
|
201
|
-
<MergedRefs count={ 2 } tagName="button" />,
|
|
202
|
-
rootElement
|
|
203
|
-
);
|
|
185
|
+
rerender( <MergedRefs count={ 2 } tagName="button" /> );
|
|
204
186
|
|
|
205
|
-
const newElement =
|
|
187
|
+
const newElement = screen.getByRole( 'button' );
|
|
206
188
|
|
|
207
189
|
// Both the node changes and the dependencies update for the second
|
|
208
190
|
// callback, so expect the old callback function to be called with null
|
|
@@ -217,7 +199,7 @@ describe( 'useMergeRefs', () => {
|
|
|
217
199
|
[ [], [ newElement ] ],
|
|
218
200
|
] );
|
|
219
201
|
|
|
220
|
-
|
|
202
|
+
unmount();
|
|
221
203
|
|
|
222
204
|
// Unmount: current callback functions should be called with null.
|
|
223
205
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -230,15 +212,13 @@ describe( 'useMergeRefs', () => {
|
|
|
230
212
|
} );
|
|
231
213
|
|
|
232
214
|
it( 'should work for dependency change after node change', () => {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
ReactDOM.render( <MergedRefs />, rootElement );
|
|
215
|
+
const { rerender, unmount } = render( <MergedRefs /> );
|
|
236
216
|
|
|
237
|
-
const originalElement =
|
|
217
|
+
const originalElement = screen.getByRole( 'list' );
|
|
238
218
|
|
|
239
|
-
|
|
219
|
+
rerender( <MergedRefs tagName="button" /> );
|
|
240
220
|
|
|
241
|
-
const newElement =
|
|
221
|
+
const newElement = screen.getByRole( 'button' );
|
|
242
222
|
|
|
243
223
|
// After a render with the original element and a second render with the
|
|
244
224
|
// new element, expect the initial callback functions to be called with
|
|
@@ -253,10 +233,7 @@ describe( 'useMergeRefs', () => {
|
|
|
253
233
|
[ [], [] ],
|
|
254
234
|
] );
|
|
255
235
|
|
|
256
|
-
|
|
257
|
-
<MergedRefs tagName="button" count={ 1 } />,
|
|
258
|
-
rootElement
|
|
259
|
-
);
|
|
236
|
+
rerender( <MergedRefs tagName="button" count={ 1 } /> );
|
|
260
237
|
|
|
261
238
|
// After a third render with a dependency change, expect the inital
|
|
262
239
|
// callback function to be called with null and the new callback
|
|
@@ -271,7 +248,7 @@ describe( 'useMergeRefs', () => {
|
|
|
271
248
|
[ [], [ newElement ] ],
|
|
272
249
|
] );
|
|
273
250
|
|
|
274
|
-
|
|
251
|
+
unmount();
|
|
275
252
|
|
|
276
253
|
// Unmount: current callback functions should be called with null.
|
|
277
254
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -285,18 +262,16 @@ describe( 'useMergeRefs', () => {
|
|
|
285
262
|
} );
|
|
286
263
|
|
|
287
264
|
it( 'should allow disabling a ref', () => {
|
|
288
|
-
const
|
|
265
|
+
const { rerender, unmount } = render( <MergedRefs disable1 /> );
|
|
289
266
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const originalElement = rootElement.firstElementChild;
|
|
267
|
+
const originalElement = screen.getByRole( 'list' );
|
|
293
268
|
|
|
294
269
|
// Render 1: ref 1 should be disabled.
|
|
295
270
|
expect( renderCallback.history ).toEqual( [
|
|
296
271
|
[ [], [ originalElement ] ],
|
|
297
272
|
] );
|
|
298
273
|
|
|
299
|
-
|
|
274
|
+
rerender( <MergedRefs disable2 /> );
|
|
300
275
|
|
|
301
276
|
// Render 2: ref 1 should be enabled and receive the ref. Note that the
|
|
302
277
|
// callback hasn't changed, so the original callback function will be
|
|
@@ -306,7 +281,7 @@ describe( 'useMergeRefs', () => {
|
|
|
306
281
|
[ [], [] ],
|
|
307
282
|
] );
|
|
308
283
|
|
|
309
|
-
|
|
284
|
+
rerender( <MergedRefs disable1 count={ 1 } /> );
|
|
310
285
|
|
|
311
286
|
// Render 3: ref 1 should again be disabled. Ref 2 to should receive a
|
|
312
287
|
// ref with the new callback function because the count has been
|
|
@@ -320,7 +295,7 @@ describe( 'useMergeRefs', () => {
|
|
|
320
295
|
[ [], [ originalElement ] ],
|
|
321
296
|
] );
|
|
322
297
|
|
|
323
|
-
|
|
298
|
+
unmount();
|
|
324
299
|
|
|
325
300
|
// Unmount: current callback functions should receive null.
|
|
326
301
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -334,18 +309,16 @@ describe( 'useMergeRefs', () => {
|
|
|
334
309
|
} );
|
|
335
310
|
|
|
336
311
|
it( 'should allow the hook being unused', () => {
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
ReactDOM.render( <MergedRefs unused />, rootElement );
|
|
312
|
+
const { rerender } = render( <MergedRefs unused /> );
|
|
340
313
|
|
|
341
|
-
const originalElement =
|
|
314
|
+
const originalElement = screen.getByRole( 'list' );
|
|
342
315
|
|
|
343
316
|
// Render 1: ref 1 should updated, ref 2 should not.
|
|
344
317
|
expect( renderCallback.history ).toEqual( [
|
|
345
318
|
[ [ originalElement ], [] ],
|
|
346
319
|
] );
|
|
347
320
|
|
|
348
|
-
|
|
321
|
+
rerender( <MergedRefs /> );
|
|
349
322
|
|
|
350
323
|
// Render 2: ref 2 should be updated as well.
|
|
351
324
|
expect( renderCallback.history ).toEqual( [
|
|
@@ -353,7 +326,7 @@ describe( 'useMergeRefs', () => {
|
|
|
353
326
|
[ [], [] ],
|
|
354
327
|
] );
|
|
355
328
|
|
|
356
|
-
|
|
329
|
+
rerender( <MergedRefs unused /> );
|
|
357
330
|
|
|
358
331
|
// Render 3: ref 2 should be updated with null
|
|
359
332
|
expect( renderCallback.history ).toEqual( [
|