Skip to content

Commit f0454d6

Browse files
committed
Fix tests
1 parent 5f51997 commit f0454d6

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

tests/unit/useOnyxTest.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,11 @@ describe('useOnyx', () => {
10901090
expect(result.current[1].status).toEqual('loaded');
10911091
});
10921092

1093-
it('should transition through loading and return value when switching from a skippable key to a valid one', async () => {
1093+
it('should return value immediately when switching from a skippable key to a valid one', async () => {
10941094
// Seed a value for the skippable key — must stay invisible to the hook
1095-
await StorageMock.setItem(`${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id`, {id: 'skippable'});
1096-
// Seed the target valid key in storage only (not in cache) so the switch goes through loading
1097-
await StorageMock.setItem(`${ONYXKEYS.COLLECTION.TEST_KEY}1`, {id: '1'});
1095+
await Onyx.set(`${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id`, {id: 'skippable'});
1096+
// Seed the target valid key
1097+
await Onyx.set(`${ONYXKEYS.COLLECTION.TEST_KEY}1`, {id: '1'});
10981098

10991099
const {result, rerender} = renderHook((key: string) => useOnyx(key), {initialProps: `${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id` as string});
11001100

@@ -1103,11 +1103,9 @@ describe('useOnyx', () => {
11031103
expect(result.current[0]).toBeUndefined();
11041104
expect(result.current[1].status).toEqual('loaded');
11051105

1106-
// Switch to a valid key whose value is in storage but not in cache — should transition through loading
1106+
// Switch to a valid key value is available immediately from cache
11071107
rerender(`${ONYXKEYS.COLLECTION.TEST_KEY}1`);
11081108

1109-
expect(result.current[1].status).toEqual('loading');
1110-
11111109
await act(async () => waitForPromisesToResolve());
11121110

11131111
expect(result.current[0]).toEqual({id: '1'});

0 commit comments

Comments
 (0)