You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a great question @chenxeed. useAuth might look like a singleton, but it sort of isn't.
Every time you render an AuthProvider, we create everything from scratch internally. Auth0 client is instantiated, state object is set up, etc. From that point onward, all children components share that same state and Auth0 client via context.
So if you wanted to test this, my recommendation is to render a new AuthProvider for every test. That ensures you get a clean test every time.
If you want to test that multiple components correctly share that state, then I'm not really sure. I suspect you're then going into the territory of testing React itself.
That said, I should probably add some proper tests to this library :D
Hi,
my question might be specific to the general way of testing Context API in React that acts as a singleton.
I believe it's a great help to showcase how is this
useAuth
library is going to be tested since it's (seems like) a singleton. Thanks!The text was updated successfully, but these errors were encountered: