Skip to content

Commit

Permalink
Add tests showing collection callback is called with undefined when s…
Browse files Browse the repository at this point in the history
…etting null on a collection key
  • Loading branch information
iwiznia committed Nov 14, 2024
1 parent 11407f6 commit ee51de1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit/onyxTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,26 @@ describe('Onyx', () => {
);
});

it('should not call the callback with undefined to a collection subscriber using waitForCollectionCallback when deleting one of the collection keys', () => {
const mockCallback = jest.fn();

// Given an Onyx.connect call with waitForCollectionCallback=true
connection = Onyx.connect({
key: ONYX_KEYS.COLLECTION.TEST_POLICY,
waitForCollectionCallback: true,
callback: mockCallback,
});
return (
waitForPromisesToResolve()
// When mergeCollection is called with an updated collection
.then(() => Onyx.set(`${ONYX_KEYS.COLLECTION.TEST_POLICY}${1}`, null))
.then(() => {
// AND the value for the second call should be collectionUpdate
expect(mockCallback).toHaveBeenCalledWith({});
})
);
});

it('should return a promise when set() called with the same value and there is no change', () => {
const promiseOne = Onyx.set('test', 'pizza');
expect(promiseOne).toBeInstanceOf(Promise);
Expand Down

0 comments on commit ee51de1

Please sign in to comment.