From ee51de118ffb737b1b5a8c33be600bfa2cd8a823 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 14 Nov 2024 11:12:01 -0300 Subject: [PATCH] Add tests showing collection callback is called with undefined when setting null on a collection key --- tests/unit/onyxTest.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/onyxTest.ts b/tests/unit/onyxTest.ts index 08e3600b..64d85961 100644 --- a/tests/unit/onyxTest.ts +++ b/tests/unit/onyxTest.ts @@ -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);