Skip to content

Commit 48a5f56

Browse files
ctrlplusbclaude
andcommitted
fix(tests): make useStoreRehydrated suspense test deterministic (#1032)
The test relied on a setTimeout-based async memory storage (18ms wait) to keep the rehydration promise pending while asserting the Suspense fallback. Under coverage instrumentation in CI the timer could fire inside the surrounding act() block, so React unsuspended before the Loading assertion ran. Switches to a manually-controlled deferred promise so the rehydration gate is held until the test explicitly releases it. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fa8912d commit 48a5f56

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

tests/persist.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,15 @@ test('multiple stores', async () => {
933933

934934
test('useStoreRehydrated', async () => {
935935
// ARRANGE
936-
const memoryStorage = createMemoryStorage(undefined, { async: true });
936+
let releaseGetItem;
937+
const getItemPromise = new Promise((resolve) => {
938+
releaseGetItem = resolve;
939+
});
940+
const memoryStorage = {
941+
getItem: () => getItemPromise,
942+
setItem: () => undefined,
943+
removeItem: () => undefined,
944+
};
937945
const store = sharedMakeStore({
938946
storage: memoryStorage,
939947
});
@@ -966,6 +974,7 @@ test('useStoreRehydrated', async () => {
966974

967975
// ACT
968976
await act(async () => {
977+
releaseGetItem(undefined);
969978
await store.persist.resolveRehydration();
970979
});
971980

0 commit comments

Comments
 (0)