Skip to content

Commit ee51de1

Browse files
committed
Add tests showing collection callback is called with undefined when setting null on a collection key
1 parent 11407f6 commit ee51de1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/unit/onyxTest.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,26 @@ describe('Onyx', () => {
10771077
);
10781078
});
10791079

1080+
it('should not call the callback with undefined to a collection subscriber using waitForCollectionCallback when deleting one of the collection keys', () => {
1081+
const mockCallback = jest.fn();
1082+
1083+
// Given an Onyx.connect call with waitForCollectionCallback=true
1084+
connection = Onyx.connect({
1085+
key: ONYX_KEYS.COLLECTION.TEST_POLICY,
1086+
waitForCollectionCallback: true,
1087+
callback: mockCallback,
1088+
});
1089+
return (
1090+
waitForPromisesToResolve()
1091+
// When mergeCollection is called with an updated collection
1092+
.then(() => Onyx.set(`${ONYX_KEYS.COLLECTION.TEST_POLICY}${1}`, null))
1093+
.then(() => {
1094+
// AND the value for the second call should be collectionUpdate
1095+
expect(mockCallback).toHaveBeenCalledWith({});
1096+
})
1097+
);
1098+
});
1099+
10801100
it('should return a promise when set() called with the same value and there is no change', () => {
10811101
const promiseOne = Onyx.set('test', 'pizza');
10821102
expect(promiseOne).toBeInstanceOf(Promise);

0 commit comments

Comments
 (0)