Skip to content

Receiving stale data intermittently even after overriding endpoint and resetting handlers #717

Closed
@NickLewry

Description

@NickLewry

Environment

Name Version
msw 0^0.24.2
node 14.15
OS Mac OS Catalina 10.15.7

Request handlers

I have created a new project to reproduce this issue: https://github.com/NickLewry/next-msw-swr

Current behavior

Currently I am being served the default handler response in my 2nd test even though I am overriding that response with server.use(). Weirdly this issue has proved to be intermittent as occasionally the override will work and the tests will pass. Another strange observation is if I move the override server.use() to the first test then I am served that response in my 2nd test even though I am calling server.resetHandlers() after each test.

initially I thought it had to do with SWR caching the response so I implemented the cache.clear() after each test which has not solved the issue and I also double checked the cache was empty at the beginning of the 2nd test by logging out cache.keys(). I then also wrote a Wrapper component for <SWRConfig> setting the dedupeInterval to 0 as I thought requests were getting grouped but I don't think that is the case.

This is an intermittent issue:

  1. If you run the tests for the first time they will pass, but as soon as you run them again immediately after (or have watch mode enabled and trigger multiple reruns by saving) you will see a failure as the wrong data is being served by the handler.

Expected behavior

I would expect the override to work in my second test by serving the updated content and for the handlers to be reset after each test.

Screenshots

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscope:nodeRelated to MSW running in Node

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions