-
-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to reset atom in unit test? #496
Comments
atomWithReset is not primarily for testing. Provider is. According to https://react-hooks-testing-library.com/usage/advanced-hooks#context import { Provider } from 'jotai'
const wrapper = ({ children }) => <Provider>{children}</Provider> This may help. |
My comment was too naive. Here I made the codesandbox example. For the |
Thanks, it works perfectly now. the |
Yeah, we should write some docs wrt #252. This issue helped understanding the usage. Thanks! |
besides, I think it's better to write logic code in custom hooks separately, instead of writing theme in components. |
I'd personally do that even with useState. It's more about how you organize your code in React in general. |
I know I can follow the doc here: https://docs.pmnd.rs/jotai/guides/resettable in my code to achieve this.
But I'm writing unit tests in my project, which it appears that the atom value would be persisted somehow, but I think all the atom values used in different unit tests should not be the same.
my hook is defined below:
and my unit test is below:
The text was updated successfully, but these errors were encountered: