Test Utils + Vitest + MSW - potential caching issue
I'm using a combination of
"@nuxt/test-utils": "^3.12.1",
"@nuxt/test-utils": "^3.12.1",
,
"vitest": "^1.5.0",
"vitest": "^1.5.0",
and
"msw": "^2.2.14",
"msw": "^2.2.14",
to test my Nuxt application.
Everything works great, except I'm running into an issue when attempting to mock a specific http request using MSW (https://mswjs.io/):
it('should retry fetching the next match after a delay', async () => { mswServer.use( http.get(lolesports.GET_SCHEDULE_ENDPOINT, () => { return new HttpResponse(null, { status: 401, }) }) ) const setTimeoutSpy = vi.spyOn(global, 'setTimeout') await getNextMatchFromLoop() vi.advanceTimersByTime(intervalTimes.fiveSeconds) expect(setTimeoutSpy).toHaveBeenCalledTimes(1) })
it('should retry fetching the next match after a delay', async () => { mswServer.use( http.get(lolesports.GET_SCHEDULE_ENDPOINT, () => { return new HttpResponse(null, { status: 401, }) }) ) const setTimeoutSpy = vi.spyOn(global, 'setTimeout') await getNextMatchFromLoop() vi.advanceTimersByTime(intervalTimes.fiveSeconds) expect(setTimeoutSpy).toHaveBeenCalledTimes(1) })
In this case, I'm trying to do a one-off network override (https://mswjs.io/docs/best-practices/network-behavior-overrides). This doesn't actually override the HTTP request, and instead provides the response from my initial mock that is passed to my MSW server.
I'm happy to get deeper into the details if you're interested, but the question I have is related to caching.
I haven't been able to find anywhere to disable or force-reset the vitest or nuxt test-utils cache besides https://vitest.dev/config/#cache, which had no effect.