axios-hooks icon indicating copy to clipboard operation
axios-hooks copied to clipboard

Response contamination when using axios-hooks with testing-library due to LRU cache

Open eelkevdbos opened this issue 2 years ago • 3 comments

The useAxios hook uses a LRU cache by default. When writing tests, the cache is not invalidated between tests (at least not with testing-library). This makes previous responses "bleed" into subsequent tests. This behavior can easily be disabled in the test suite setup with the following:

beforeAll(() => {
    useAxios.configure({cache: false})
})

I'm not sure if it deserves a place in the docs, but I thought I would mention it here to -- possibly -- save someone a bit of time.

Reference to the issue I originally landed on: https://github.com/testing-library/react-testing-library/issues/716

eelkevdbos avatar Feb 03 '22 17:02 eelkevdbos

It would be great to include this in the docs. Would you like to send a PR?

simoneb avatar Feb 03 '22 17:02 simoneb

Yes, I'll work on one 👍

eelkevdbos avatar Feb 03 '22 18:02 eelkevdbos

@eelkevdbos any updates?

simoneb avatar Feb 16 '22 11:02 simoneb

@simoneb, is this still relevant? If it is, I can make some time today for a PR on the docs.

eelkevdbos avatar Aug 21 '23 12:08 eelkevdbos

@eelkevdbos it would be great if you could do it!

simoneb avatar Aug 21 '23 13:08 simoneb

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your optic bot 📦🚀

github-actions[bot] avatar Sep 17 '23 10:09 github-actions[bot]