@@ -7,6 +7,7 @@ const ONYX_KEYS = {
77 COLLECTION : {
88 TEST_KEY : 'test_' ,
99 TEST_CONNECT_COLLECTION : 'test_connect_collection_' ,
10+ TEST_POLICY : 'test_policy_' ,
1011 } ,
1112} ;
1213
@@ -470,8 +471,7 @@ describe('Onyx', () => {
470471 } ) ;
471472
472473 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 ) ;
474+ const mockCallback = jest . fn ( ) ;
475475
476476 // GIVEN some initial collection data
477477 const initialCollectionData = {
@@ -493,7 +493,7 @@ describe('Onyx', () => {
493493 return waitForPromisesToResolve ( )
494494 . then ( ( ) => {
495495 // WHEN we connect to that collection with waitForCollectionCallback = true
496- Onyx . connect ( {
496+ connectionID = Onyx . connect ( {
497497 key : ONYX_KEYS . COLLECTION . TEST_CONNECT_COLLECTION ,
498498 waitForCollectionCallback : true ,
499499 callback : mockCallback ,
@@ -508,29 +508,32 @@ describe('Onyx', () => {
508508 } ) ;
509509
510510 it ( 'should return all collection keys as a single object when updating a collection key with waitForCollectionCallback = true' , ( ) => {
511- const valuesReceived = { } ;
512- const mockCallback = jest . fn ( data => valuesReceived [ data . ID ] = data . value ) ;
511+ const mockCallback = jest . fn ( ) ;
513512 const collectionUpdate = {
514- test_connect_collection_3 : { ID : 234 , value : 'three ' } ,
515- test_connect_collection_4 : { ID : 123 , value : 'four ' } ,
513+ test_policy_1 : { ID : 234 , value : 'one ' } ,
514+ test_policy_2 : { ID : 123 , value : 'two ' } ,
516515 } ;
517516
518517 // GIVEN an Onyx.connect call with waitForCollectionCallback=true
519- Onyx . connect ( {
520- key : ONYX_KEYS . COLLECTION . TEST_CONNECT_COLLECTION ,
518+ connectionID = Onyx . connect ( {
519+ key : ONYX_KEYS . COLLECTION . TEST_POLICY ,
521520 waitForCollectionCallback : true ,
522521 callback : mockCallback ,
523522 } ) ;
524523 return waitForPromisesToResolve ( )
525524 . then ( ( ) => {
526525 // WHEN we update the collection, e.g. the API returns a response
527- Onyx . mergeCollection ( ONYX_KEYS . COLLECTION . TEST_CONNECT_COLLECTION , collectionUpdate ) ;
526+ Onyx . mergeCollection ( ONYX_KEYS . COLLECTION . TEST_POLICY , collectionUpdate ) ;
528527 return waitForPromisesToResolve ( ) ;
529528 } )
530529 . then ( ( ) => {
531- // THEN we expect the callback to have called twice (once for the initial connect call and once for the collection update)
532- // AND the value should be equal to collectionUpdate
530+ // THEN we expect the callback to have called twice, once for the initial connect call + once for the collection update
533531 expect ( mockCallback . mock . calls . length ) . toBe ( 2 ) ;
532+
533+ // AND the value for the first call should be null since the collection was not initialized at that point
534+ expect ( mockCallback . mock . calls [ 0 ] [ 0 ] ) . toBe ( null ) ;
535+
536+ // AND the value for the second call should be collectionUpdate since the collection was updated
534537 expect ( mockCallback . mock . calls [ 1 ] [ 0 ] ) . toEqual ( collectionUpdate ) ;
535538 } ) ;
536539 } ) ;
0 commit comments