diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index 0f93730a9..7781f5633 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -1377,7 +1377,7 @@ function subscribeToKey(connectOptions: ConnectOptions { }); describe('misc', () => { + it('should initially return loading state while loading non-existent key, and then return `undefined` and loaded state', async () => { + const {result} = renderHook(() => useOnyx(ONYXKEYS.TEST_KEY)); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loading'); + + await act(async () => waitForPromisesToResolve()); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loaded'); + }); + + it('should initially return loading state while loading non-existent collection key, and then return `undefined` and loaded state', async () => { + const {result} = renderHook(() => useOnyx(ONYXKEYS.COLLECTION.TEST_KEY)); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loading'); + + await act(async () => waitForPromisesToResolve()); + + expect(result.current[0]).toBeUndefined(); + expect(result.current[1].status).toEqual('loaded'); + }); + it('should return value and loaded state when loading cached key', async () => { Onyx.set(ONYXKEYS.TEST_KEY, 'test');