@@ -969,24 +969,16 @@ describe('FragmentRefs', () => {
969
969
970
970
describe ( 'compareDocumentPosition' , ( ) => {
971
971
function expectPosition ( position , spec ) {
972
- expect ( ( position & Node . DOCUMENT_POSITION_PRECEDING ) !== 0 ) . toBe (
973
- spec . preceding ,
974
- ) ;
975
- expect ( ( position & Node . DOCUMENT_POSITION_FOLLOWING ) !== 0 ) . toBe (
976
- spec . following ,
977
- ) ;
978
- expect ( ( position & Node . DOCUMENT_POSITION_CONTAINS ) !== 0 ) . toBe (
979
- spec . contains ,
980
- ) ;
981
- expect ( ( position & Node . DOCUMENT_POSITION_CONTAINED_BY ) !== 0 ) . toBe (
982
- spec . containedBy ,
983
- ) ;
984
- expect ( ( position & Node . DOCUMENT_POSITION_DISCONNECTED ) !== 0 ) . toBe (
985
- spec . disconnected ,
986
- ) ;
987
- expect (
988
- ( position & Node . DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ) !== 0 ,
989
- ) . toBe ( spec . implementationSpecific ) ;
972
+ const positionResult = {
973
+ following : ( position & Node . DOCUMENT_POSITION_FOLLOWING ) !== 0 ,
974
+ preceding : ( position & Node . DOCUMENT_POSITION_PRECEDING ) !== 0 ,
975
+ contains : ( position & Node . DOCUMENT_POSITION_CONTAINS ) !== 0 ,
976
+ containedBy : ( position & Node . DOCUMENT_POSITION_CONTAINED_BY ) !== 0 ,
977
+ disconnected : ( position & Node . DOCUMENT_POSITION_DISCONNECTED ) !== 0 ,
978
+ implementationSpecific :
979
+ ( position & Node . DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ) !== 0 ,
980
+ } ;
981
+ expect ( positionResult ) . toEqual ( spec ) ;
990
982
}
991
983
// @gate enableFragmentRefs
992
984
it ( 'returns the relationship between the fragment instance and a given node' , async ( ) => {
@@ -1265,5 +1257,56 @@ describe('FragmentRefs', () => {
1265
1257
} ,
1266
1258
) ;
1267
1259
} ) ;
1260
+
1261
+ // @gate enableFragmentRefs
1262
+ it ( 'returns disconnected for comparison with an unmounted fragment instance' , async ( ) => {
1263
+ const fragmentRef = React . createRef ( ) ;
1264
+ const containerRef = React . createRef ( ) ;
1265
+ const root = ReactDOMClient . createRoot ( container ) ;
1266
+
1267
+ function Test ( { mount} ) {
1268
+ return (
1269
+ < div ref = { containerRef } >
1270
+ { mount && (
1271
+ < Fragment ref = { fragmentRef } >
1272
+ < div > </ div >
1273
+ </ Fragment >
1274
+ ) }
1275
+ </ div >
1276
+ ) ;
1277
+ }
1278
+
1279
+ await act ( ( ) => root . render ( < Test mount = { true } /> ) ) ;
1280
+
1281
+ const fragmentHandle = fragmentRef . current ;
1282
+
1283
+ expectPosition (
1284
+ fragmentHandle . compareDocumentPosition ( containerRef . current ) ,
1285
+ {
1286
+ preceding : true ,
1287
+ following : false ,
1288
+ contains : true ,
1289
+ containedBy : false ,
1290
+ disconnected : false ,
1291
+ implementationSpecific : false ,
1292
+ } ,
1293
+ ) ;
1294
+
1295
+ await act ( ( ) => {
1296
+ root . render ( < Test mount = { false } /> ) ;
1297
+ } ) ;
1298
+
1299
+ expectPosition (
1300
+ fragmentHandle . compareDocumentPosition ( containerRef . current ) ,
1301
+ {
1302
+ preceding : false ,
1303
+ following : false ,
1304
+ contains : false ,
1305
+ containedBy : false ,
1306
+ disconnected : true ,
1307
+ implementationSpecific : false ,
1308
+ } ,
1309
+ ) ;
1310
+ } ) ;
1268
1311
} ) ;
1269
1312
} ) ;
0 commit comments