enzyme: mount Suspense and throw promise - Enzyme Internal Error: unknown node with tag 2
Current behavior
Getting error Enzyme Internal Error: unknown node with tag 2
from mounting Suspense
component with child component that throws promise:
import React, { Suspense } from "react";
const Message = props => <div>Hello Enzyme!</div>
const Loading = props => <div>loading...</div>
const Thrower = props => {
throw new Promise(resolve => {
setTimeout(resolve, 1000);
});
};
describe("integration with Suspense component", () => {
test("should render Message component", () => {
const wrapper = mount(
<Suspense fallback={<Loading />}>
<Message />
</Suspense>
);
expect(wrapper.find(Message)).toExist(); // ✅ passes
});
test("should render Loading component", () => {
const wrapper = mount(
<Suspense fallback={<Loading />}>
<Thrower />
</Suspense>
);
expect(wrapper.find(Loading)).toExist(); // ❌ Enzyme Internal Error: unknown node with tag 2
});
})
trace:
Enzyme Internal Error: unknown node with tag 2
20 |
21 | test("should render Loading component", () => {
> 22 | const wrapper = mount(
| ^
23 | <Suspense fallback={<Loading />}>
24 | <Thrower />
25 | </Suspense>
at _toTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:254:13)
at toTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:267:12)
at childrenToTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:227:14)
at Array.map (<anonymous>)
at map (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:269:27)
at childrenToTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:248:19)
at toTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:267:12)
at childrenToTree (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:169:19)
at Object.toTree [as getNode] (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:448:11)
at new getNode (node_modules/enzyme/src/ReactWrapper.js:117:44)
at mount (node_modules/enzyme/src/mount.js:10:10)
at Object.mount (__tests__/Suspense.spec.js:22:21)
Expected behavior
No error
Your environment
API
- shallow
- mount
- render
Version
library | version |
---|---|
enzyme | 3.10.0 |
jest-enzyme | 7.0.2 |
react | 16.8.6 |
react-dom | 16.8.6 |
react-test-renderer | 16.8.6 |
adapter (below) | 1.14.0 |
Adapter
- enzyme-adapter-react-16
- enzyme-adapter-react-16.3
- enzyme-adapter-react-16.2
- enzyme-adapter-react-16.1
- enzyme-adapter-react-15
- enzyme-adapter-react-15.4
- enzyme-adapter-react-14
- enzyme-adapter-react-13
- enzyme-adapter-react-helper
- others ( )
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 19 (7 by maintainers)
Hi there, is there any update on the issue? Looking forward for it to be fixed!
Failing without any async nor Promise.
@artola if you can make a PR with passing tests, then that sounds awesome.
hmm, in that case perhaps the “thrown promise” case isn’t something we’re handling properly.
Throwing promise inside render is supported by React Suspense. See pull request in React repo Accept promise as element type