@@ -6,6 +6,7 @@ const ONYX_KEYS = {
66 OTHER_TEST : 'otherTest' ,
77 COLLECTION : {
88 TEST_KEY : 'test_' ,
9+ TEST_CONNECT_COLLECTION : 'test_connect_collection_' ,
910 } ,
1011} ;
1112
@@ -467,4 +468,43 @@ describe('Onyx', () => {
467468 expect ( error . message ) . toEqual ( 'Invalid boolean key provided in Onyx update. Onyx key must be of type string.' ) ;
468469 }
469470 } ) ;
471+
472+ it ( 'should return all collection keys as a single object when waitForCollectionCallback = true' , ( ) => {
473+ const valuesReceived = { } ;
474+ const mockCallback = jest . fn ( data => valuesReceived [ data . ID ] = data . value ) ;
475+
476+ // GIVEN some collection data
477+ const collectionData = {
478+ test_connect_collection_1 : {
479+ ID : 123 ,
480+ value : 'one' ,
481+ } ,
482+ test_connect_collection_2 : {
483+ ID : 234 ,
484+ value : 'two' ,
485+ } ,
486+ test_connect_collection_3 : {
487+ ID : 345 ,
488+ value : 'three' ,
489+ } ,
490+ } ;
491+ Onyx . mergeCollection ( ONYX_KEYS . COLLECTION . TEST_CONNECT_COLLECTION , collectionData ) ;
492+ return waitForPromisesToResolve ( )
493+ . then ( ( ) => {
494+ // WHEN we call Onyx.connect with the waitForCollectionCallback = true param
495+ connectionID = Onyx . connect ( {
496+ key : ONYX_KEYS . COLLECTION . TEST_CONNECT_COLLECTION ,
497+ waitForCollectionCallback : true ,
498+ callback : mockCallback ,
499+ } ) ;
500+ return waitForPromisesToResolve ( ) ;
501+ } )
502+ . then ( ( ) => {
503+ // THEN the callback should be triggered only once
504+ expect ( mockCallback . mock . calls . length ) . toBe ( 1 ) ;
505+
506+ // AND all the collection data should be returned as a single object
507+ expect ( mockCallback . mock . calls [ 0 ] [ 0 ] ) . toEqual ( collectionData ) ;
508+ } ) ;
509+ } ) ;
470510} ) ;
0 commit comments