Open james-reed-toshi opened 2 years ago
Hi @james-reed-toshi, try wrapping the components that you render in:
<SWRConfig value={{provider: () => new Map(), dedupingInterval: 0}}>
<YourComponent/>
</SWRConfig>
This will disable all caching and deduping for those components and fixed the issue for me.
@embeddedt As mentioned, I'm aware that is an option, but it still doesn't explain why SWR doesn't eventually return me the new return value for the endpoint.
Bug report
Description / Observed Behavior
I have a simple SWR/msw/react/jest setup where in one test, I have instructed MSW to return with one value from an endpoint, and in the other test, to return with a different value. SWR does not respect the new value returned from the endpoint mocked by MSW, and my test fails.
Expected Behavior
I would expect SWR, with caching, to first return the cached result, but then to return the new result given that it's different, meaning that both tests would eventually pass. I have added long timeouts and sleeps to ensure that it isn't just a timing issue on these tests.
Repro Steps / Code Example
swr_caching_react_tests.zip To run, just download, run
yarn
thenyarn test
. All versions of libs used are in package.jsonAdditional Context
I understand that SWR puts forward the idea of wrapping these tests with a config that has an empty provider - however, I don't see why SWR is not eventually seeing the new value coming forth in the MSW handler for the second test.