Skip to content

Commit 3f05c0b

Browse files
authored
test(router-core): fix flakiness of store-updates 'preload then navigate' test (#4995)
It turns out the 'hover preload, then navigate, w/ async loaders' test in `packages/react-router/tests/store-updates-during-navigation.test.tsx` was sometimes (but very rarely) yielding 16 updates instead of the expected 15. This PR makes minimal changes to this test so that it's now reliably 14. I'm not exactly sure where we lost that 1 update, so we might not be measuring exactly the same thing. But it's still worth it to have a robust test suite. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved reliability of hover preloading and navigation behavior tests by introducing realistic loader delays and aligning interaction timing, reducing flakiness. * Updated assertions for store updates during navigation to reflect observed behavior, ensuring more stable and predictable test outcomes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 83ab173 commit 3f05c0b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/react-router/tests/store-updates-during-navigation.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ describe("Store doesn't update *too many* times during navigation", () => {
189189
test('hover preload, then navigate, w/ async loaders', async () => {
190190
const { select } = setup({
191191
beforeLoad: () => Promise.resolve({ foo: 'bar' }),
192-
loader: () => Promise.resolve({ hello: 'world' }),
192+
loader: () => resolveAfter(100, { hello: 'world' }),
193193
})
194194

195195
const link = await waitFor(() =>
196196
screen.getByRole('link', { name: 'Posts' }),
197197
)
198198
const before = select.mock.calls.length
199199
fireEvent.focus(link)
200+
await new Promise((resolve) => setTimeout(resolve, 50))
200201
fireEvent.click(link)
201202
const title = await waitFor(() =>
202203
screen.getByRole('heading', { name: /Title$/ }),
@@ -208,6 +209,6 @@ describe("Store doesn't update *too many* times during navigation", () => {
208209
// This number should be as small as possible to minimize the amount of work
209210
// that needs to be done during a navigation.
210211
// Any change that increases this number should be investigated.
211-
expect(updates).toBe(15)
212+
expect(updates).toBe(14)
212213
})
213214
})

0 commit comments

Comments
 (0)