Skip to content

Commit b348a7d

Browse files
committed
split tests
1 parent d0344c4 commit b348a7d

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

tests/unit/onyxTest.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,6 @@ describe('Onyx', () => {
489489
},
490490
};
491491

492-
// AND an API response for that collection
493-
const apiResponse = {
494-
...initialCollectionData,
495-
test_connect_collection_4: {ID: 123, value: 'four'},
496-
};
497-
498492
Onyx.mergeCollection(ONYX_KEYS.COLLECTION.TEST_CONNECT_COLLECTION, initialCollectionData);
499493
return waitForPromisesToResolve()
500494
.then(() => {
@@ -510,17 +504,34 @@ describe('Onyx', () => {
510504
// THEN we expect the callback to be called only once and the initial stored value to be initialCollectionData
511505
expect(mockCallback.mock.calls.length).toBe(1);
512506
expect(mockCallback.mock.calls[0][0]).toEqual(initialCollectionData);
507+
});
508+
});
513509

510+
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);
513+
const collectionUpdate = {
514+
test_connect_collection_3: {ID: 234, value: 'three'},
515+
test_connect_collection_4: {ID: 123, value: 'four'},
516+
};
517+
518+
// GIVEN an Onyx.connect call with waitForCollectionCallback=true
519+
Onyx.connect({
520+
key: ONYX_KEYS.COLLECTION.TEST_CONNECT_COLLECTION,
521+
waitForCollectionCallback: true,
522+
callback: mockCallback,
523+
});
524+
return waitForPromisesToResolve()
525+
.then(() => {
514526
// WHEN we update the collection, e.g. the API returns a response
515-
Onyx.mergeCollection(ONYX_KEYS.COLLECTION.TEST_CONNECT_COLLECTION, apiResponse);
527+
Onyx.mergeCollection(ONYX_KEYS.COLLECTION.TEST_CONNECT_COLLECTION, collectionUpdate);
516528
return waitForPromisesToResolve();
517529
})
518530
.then(() => {
519-
// THEN we expect the callback to have called twice, once for the initial connect call and once for the API response
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
520533
expect(mockCallback.mock.calls.length).toBe(2);
521-
522-
// AND all the updated collection data should be returned as a single object
523-
expect(mockCallback.mock.calls[1][0]).toEqual(apiResponse);
534+
expect(mockCallback.mock.calls[1][0]).toEqual(collectionUpdate);
524535
});
525536
});
526537
});

0 commit comments

Comments
 (0)