-
-
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
Error diving through react-redux connected components #2106
Comments
The currently released version of enzyme doesn't support createContext; the next release will. I believe you'll need to stick to v5 of react-redux until enzyme is released. |
Ok... I've been following the issues linked in #1647 (comment). Have those merged PRs not made it into a release yet or are they not enough for full support of diving with the new Context API? Good to know anyways. I'll stop wasting time trying to get the Thanks for the quick reply :) And thanks for the continuing work on the context API stuff! |
They've not made it into a release yet. |
Ah ok. That makes sense. I saw the adapter releases go out afterwards and guess I assumed the code changes were only in the adaptors. Thanks. |
@ljharb hi, when release the next? |
When it’s ready and when i have the time; not sooner, I’m afraid. |
You noted that enzyme does not yet support useContext, but the error Wrote a quick test like this: const Context = React.createContext(0);
const Component = () => {
const ctxVal = React.useContext(Context);
return <div>{ctxVal}</div>;
};
const tree = (
<Context.Provider value={5}>
<Component />
</Context.Provider>
);
const wrapper = shallow(tree);
expect(wrapper).toMatchInlineSnapshot(`<Component />`);
expect(
wrapper
.find("Component")
.at(0)
.dive()
).toMatchInlineSnapshot(`
<div>
0
</div>
`);
const wrapperMounted = mount(tree);
expect(wrapperMounted).toMatchInlineSnapshot(`
<Component>
<div>
5
</div>
</Component>
`); Obviously a shallow render (and diving into the component with useContext) is getting the wrong value (0, the default context value, instead of 5), where mount worked correctly. However, this is not the error above: I realize this might be just as much on react-redux's end as enzyme's, but apart from other hooks being used in ConnectFunction, I'm having trouble seeing what could be so unsupported that enzyme can't even register ConnectFunction as a component. So what makes the ConnectFunction "not a component" in enzyme's eyes? |
@matthewdavidrodgers because the code in enzyme to recognize it hasn't been released yet. |
v3.10.0 has now been released. |
Still something is wrong with https://codesandbox.io/s/old-currying-4lme5 Will create new issue as soon as figure out some more particular test case. |
Current behavior
I get a
ShallowWrapper::dive() can only be called on components
error when trying to.dive()
through a component wrapped inreact-redux
'sconnect
function.See demo at https://codesandbox.io/s/v33j14k0jl
Expected behavior
I should be able to dive through connected components and shallow render the component's contents. I know this worked as of
react-redux
5.1.1
. They have transitioned to the new the new React Context API since. If this belongs as an issue in thereact-redux
repo, I'll recreate it there.Your environment
Running demo on CodeSandbox
I appreciate the recent work to get the new Context APIs working and they have worked for every other dependency I've upgraded in our React Native app (
react-i18next
was a crucial one). However something seems different withreact-redux
. They could have a different/unique implementation. Thanks for looking into this :)API
Version
Adapter
The text was updated successfully, but these errors were encountered: