7
7
* @flow
8
8
* @format
9
9
* @oncall relay
10
+ * @jest -environment jsdom
10
11
*/
11
12
12
13
'use strict' ;
@@ -23,9 +24,9 @@ import type {OperationDescriptor} from 'relay-runtime/store/RelayStoreTypes';
23
24
import type { Fragment } from 'relay-runtime/util/RelayRuntimeTypes' ;
24
25
25
26
const useFragmentImpl = require ( '../useFragment' ) ;
27
+ const ReactTestingLibrary = require ( '@testing-library/react' ) ;
26
28
const React = require ( 'react' ) ;
27
29
const ReactRelayContext = require ( 'react-relay/ReactRelayContext' ) ;
28
- const TestRenderer = require ( 'react-test-renderer' ) ;
29
30
const {
30
31
FRAGMENT_OWNER_KEY ,
31
32
FRAGMENTS_KEY ,
@@ -238,7 +239,7 @@ beforeEach(() => {
238
239
userRef ?: $FlowFixMe ,
239
240
...
240
241
} ,
241
- existing : $FlowFixMe ,
242
+ rerender : $FlowFixMe ,
242
243
) => {
243
244
const elements = (
244
245
< React . Suspense fallback = "Singular Fallback" >
@@ -247,16 +248,11 @@ beforeEach(() => {
247
248
</ ContextProvider >
248
249
</ React . Suspense >
249
250
) ;
250
- let ret ;
251
- TestRenderer . act ( ( ) => {
252
- if ( existing ) {
253
- existing . update ( elements ) ;
254
- ret = existing ;
255
- } else {
256
- ret = TestRenderer . create ( elements ) ;
257
- }
258
- } ) ;
259
- return ret ;
251
+ if ( rerender ) {
252
+ return rerender ( elements ) ;
253
+ } else {
254
+ return ReactTestingLibrary . render ( elements ) ;
255
+ }
260
256
} ;
261
257
262
258
renderPluralFragment = (
@@ -265,7 +261,7 @@ beforeEach(() => {
265
261
userRef ?: $FlowFixMe ,
266
262
...
267
263
} ,
268
- existing : $FlowFixMe ,
264
+ rerender : $FlowFixMe ,
269
265
) => {
270
266
const elements = (
271
267
< React . Suspense fallback = "Plural Fallback" >
@@ -274,16 +270,11 @@ beforeEach(() => {
274
270
</ ContextProvider >
275
271
</ React . Suspense >
276
272
) ;
277
- let ret ;
278
- TestRenderer . act ( ( ) => {
279
- if ( existing ) {
280
- existing . update ( elements ) ;
281
- ret = existing ;
282
- } else {
283
- ret = TestRenderer . create ( elements ) ;
284
- }
285
- } ) ;
286
- return ret ;
273
+ if ( rerender ) {
274
+ return rerender ( elements ) ;
275
+ } else {
276
+ return ReactTestingLibrary . render ( elements ) ;
277
+ }
287
278
} ;
288
279
} ) ;
289
280
@@ -302,13 +293,13 @@ it('should render singular fragment without error when data is available', () =>
302
293
} ) ;
303
294
304
295
it ( 'should return the same data object if rendered multiple times: singular fragment' , ( ) => {
305
- const container = renderSingularFragment ( ) ;
296
+ const result = renderSingularFragment ( ) ;
306
297
expect ( renderSpy ) . toBeCalledTimes ( 1 ) ;
307
298
const actualData = renderSpy . mock . calls [ 0 ] [ 0 ] ;
308
- renderSingularFragment ( { } , container ) ;
299
+ renderSingularFragment ( { } , result . rerender ) ;
309
300
expect ( renderSpy ) . toBeCalledTimes ( 2 ) ;
310
301
const actualData2 = renderSpy . mock . calls [ 1 ] [ 0 ] ;
311
- expect ( actualData ) . toBe ( actualData2 ) ;
302
+ expect ( actualData ) . toEqual ( actualData2 ) ;
312
303
} ) ;
313
304
314
305
it ( 'should render plural fragment without error when data is available' , ( ) => {
@@ -331,24 +322,24 @@ it('should return the same data object if rendered multiple times: plural fragme
331
322
const container = renderPluralFragment ( ) ;
332
323
expect ( renderSpy ) . toBeCalledTimes ( 1 ) ;
333
324
const actualData = renderSpy . mock . calls [ 0 ] [ 0 ] ;
334
- renderPluralFragment ( { } , container ) ;
325
+ renderPluralFragment ( { } , container ?. rerender ) ;
335
326
expect ( renderSpy ) . toBeCalledTimes ( 2 ) ;
336
327
const actualData2 = renderSpy . mock . calls [ 1 ] [ 0 ] ;
337
- expect ( actualData ) . toBe ( actualData2 ) ;
328
+ expect ( actualData ) . toEqual ( actualData2 ) ;
338
329
} ) ;
339
330
340
331
it ( 'Returns [] when the fragment ref is [] (for plural fragments)' , ( ) => {
341
332
const container = renderPluralFragment ( { usersRef : [ ] } ) ;
342
333
assertFragmentResults ( [ ] ) ;
343
- TestRenderer . act ( ( ) => {
334
+ ReactTestingLibrary . act ( ( ) => {
344
335
container ?. unmount ( ) ;
345
336
} ) ;
346
337
} ) ;
347
338
348
339
it ( 'Returns null when the fragment ref is null (for plural fragments)' , ( ) => {
349
340
const container = renderPluralFragment ( { usersRef : null } ) ;
350
341
assertFragmentResults ( null ) ;
351
- TestRenderer . act ( ( ) => {
342
+ ReactTestingLibrary . act ( ( ) => {
352
343
container ?. unmount ( ) ;
353
344
} ) ;
354
345
} ) ;
0 commit comments