react-singleton-hook icon indicating copy to clipboard operation
react-singleton-hook copied to clipboard

How to cleanup between tests?

Open gtb104 opened this issue 3 years ago • 2 comments

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?

gtb104 avatar Sep 30 '21 19:09 gtb104

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?

Light-Keeper avatar Oct 20 '21 18:10 Light-Keeper

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).

arellaTV avatar Nov 05 '21 23:11 arellaTV