-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Method “type” is meant to be run on 1 node. n found instead #2549
Comments
You're using an unofficial adapter, so I'm afraid there's not really any support I can offer. enzyme does not work with react 17 yet. |
@ljharb after 2 days of debugging, I've found the root cause. This is a bug in
The following hack to workaround the
The code in
The depth traversal code of |
That’s not a bug, that is the design of “wrappingComponent” - it must only be a component that takes a single child. Your hostile language is not appreciated. |
That statement is not true? So if I created an additional wrapper that wraps everything together (now is only takes 1 child), it still throws the exact same error... It looks like
Then in the
|
Yes, you’re right it could be more precisely stated. The wrapping component must end up taking only one child, which your example still takes 3. |
@ljharb BTW, that statement is also not true because I've tried the following, and it will still fail.
You get:
Basically the You should reopen this as a bug IMHO. |
It is indeed limiting if you're using the very unidiomatic pattern of having a component that takes no children and sits somewhere just for side effects (CssBaseline and GlobalStyle, both of which should be HOCs or hooks). If you can reproduce it with the react 16 adapter, I'll be happy to reopen it - enzyme must not be used with react 17 yet, because it does not support it, so bugs are expected. |
@ljharb You can't just tell everyone who try to use Enzyme to just wrap everything at most 1 level only... I didn't create those Here is the enzyme-adapter-react-16 sandbox, reduced test case link: Below are the official documentations from various framework showcasing the valid use of "a component that takes no children". CssBaseline from Material UI GlobalStyle from styled-components Global from emotion |
Thanks; I'll reopen until I have time to dig further into it. Yes, I'm aware that the pattern is used in a few places; that doesn't mean it's a good idea. |
I found a similar case if you try to use RecoilRoot context (from https://recoiljs.org/), as it renders: <RecoilRoot>
<Batcher>
{children}
</RecoilRoot> where batcher is used internally to "The purpose of the Batcher is to observe when React batches end so that Recoil state changes can be batched." This context is needed whenever you test component that uses any of its hooks. I am writing it just as a heads up for people wanting to test testing a component that uses Recoil like: const wrapper = shallow(<MyComponent />, {
wrappingComponent: RecoilRoot,
}); that it is going to fail, so probably you should use mount instead. |
@rmontesgar-chwy i'm assuming it renders |
Update
React 16 + enzyme-adapter-react-16 reduced use case sandbox here: #2549 (comment)
Current behavior
React 17, using all the latest packages.
I follow one of the enzyme unit test workaround to include Mui's ThemeProvider + styled-components's ThemeProvider
My UT only has the following:
How can I get it to work? When I try to dump the
node
, this is what it prints out:Expected behavior
Your environment
API
Version
Adapter
The text was updated successfully, but these errors were encountered: