-
-
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
ShallowWrapper::dive fails when diving into a memoized component inside a context provider #2290
Comments
This is because a shallow wrapper "is" what the component you pass to it renders - in other words, check out: const wrapper = shallow(
<SampleContextA.Provider value={false}>
<MyComponentMemoized />
</SampleContextA.Provider>
);
console.log(wrapper.debug()); and you'll see that the wrapper is already a |
So why don't I get back a wrapper on the const wrapper = enzyme.shallow(
<SampleContextA.Provider value={false}>
<MyComponentMemoized />
</SampleContextA.Provider>
);
console.log(wrapper.debug());
try {
console.log(wrapper.dive().debug());
} catch (err) {
console.error(err.message);
}
const wrapper2 = enzyme.shallow(
<SampleContextA.Provider value={false}>
<MyComponent />
</SampleContextA.Provider>
);
console.log(wrapper2.debug());
try {
console.log(wrapper2.dive().debug());
} catch (err) {
console.error(err.message);
} I get back:
So why does calling |
Specifically because |
Ah, I see. And thanks for bearing with me here. I think I can render wrapped component with For context, I'm trying to rewrite some test rendering code so I can set the context (like the Theme) using Provider components and then shallowly render the component under test for snapshots. I have it working generally except for this snag when the component under test is memoized. |
ah, i'd say that's a bug in (Separately, I'd strongly discourage any kind of snapshot testing; it's very brittle and is only useful when making no-semantic-change refactors, which happens rarely) |
I'm getting And thanks for the guidance. I'm already skeptical of the value of snapshot tests, but we have over 600 in our repo so we can't do without them, at least for the time being. |
The workaround would be to call I'd be happy to review a PR that adds the same affordances to |
The symbol-keyed properties make that pretty convoluted 😂. I’ll work on a fix. Thanks again! |
Current behavior
Calling
throws with
TypeError: ShallowWrapper::dive() can only be called on components
. If you replace the provider wrapper with just a plain wrapper, e.g.it renders fine. It also works fine in you use MyComponent unmemoized.
Expected behavior
This code should return a ShallowWrapper to the contents of
<MyComponent />
instead of throwing.Your environment
API
Version
Adapter
Notes
I believe this is similar to but distinct from #2103. That issue addressed memoized components being wrapped by regular custom components.
The text was updated successfully, but these errors were encountered: