react-singleton-hook
react-singleton-hook copied to clipboard
How to cleanup between tests?
Using a singleton hook seems like a good solution for our particular need, but is causing some issues with testing. It appears that the singleton hook persists between tests, which is not ideal. I'd really like a way to destroy the hook upon test completion. There doesn't appear to be a way to do this?
Yes, unfortunately, the library is not designed for unit tests and I only use it with integration test libraries like cypress
.
I can add a method to reset the container state, however it still does not work with parallel tests. Is it sufficient for you? or do you have an idea how containers can be separated for parallel tests if you use them?
I ran into issues with testing too until I saw this: https://github.com/Light-Keeper/react-singleton-hook/issues/375#issuecomment-940795514
I was able to get my unit tests to work with my non-singleton version of my hook (I export both versions).