-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add option to enable strict mode render #338
Comments
I understand the motivation, but couldn't this be accomplished using the wrapper option? |
Hmm, yes. I thought you have to change the |
We would if we wanted to run concurrent mode. Maybe we will when that's stable, but I kinda don't think we will want/need to. We'll see. |
@kentcdodds sooo.... how about now? 😀 Coming to this issue as I have a hook that is behaving incorrectly in strict mode during development and I'd like to write a failing test before writing the fix. I'll look in to the wrapper option. |
I see I can add renderHook(() => useMyHook(), {
wrapper: React.StrictMode,
}); Unfortunately I'm pretty sure this is running React in production mode, or at least it isn't double-invoking I don't see a way to make Jest/react-testing-library run React in development mode, perhaps there is one and I've missed it. Obviously I want my hook to work in development mode (and I'm pretty sure there's an underlying issue here I'd need to solve anyway) and I'd really like to write a test to show this first. Any thoughts? |
I think this assumption was due to React 17 silencing the console during double invoking. Jest runs React with NODE_ENV=test by default, which enables development flags, so...
...seems to be all I need to do to test my hook works when double invoking 😓 |
Yes, The wrapper option can, but sometimes we need it for other components (e.g. also, I think it could be good that we have a strict option enabled by default |
Is there a reason not to enable this by default? Considering Create React App and Vite already default to enabling it. Reopening this to make the discussion more visibile. |
Not a fan of altering the test input. Especially since StrictMode will break perfectly fine test (e.g. asserting the number of console calls). The general advise has always been to use an internal wrapper instead. That is a good place to add StrictMode (we did that in MUI). |
Trying to write some tests for a hook that misbehaves in strict mode and can't figure out how to use wrapper along with calls to rerender. const { rerender } = renderHook((dep) => useSomeHook(dep), {
initialProps: 1,
wrapper: StrictMode
});
rerender(2);
Edit const { rerender } = renderHook(({ value }) => useSomeHook(value), {
initialProps: { value: 1, children: null },
wrapper: StrictMode,
});
rerender({ value: 2, children: null }); But that does seem fairly verbose. |
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Yeah let's do this. I think it's currently a bit too verbose if you want StrictMode and a custom Not sure if we want to go with |
We could use the same name as Next's boolean option: |
The react prefix feels redundant here but using something familiar is a good enough argument for me to lean towards And this option could also take its default from the configuration. That way verbosity isn't too much of an issue since you can likely opt-into StrictMode and then slowly fix the |
My primary concern with
Are you referring to some existing config like |
The one we have in |
Can I try this issue? |
Fixed in #1241 |
Why: to test that components work in concurrent React
The text was updated successfully, but these errors were encountered: