React Lazy tests failing. Error: Method “props” is meant to be run on 1 node. 0 found instead.
See original GitHub issueYour environment
Macos, Linux
API
- shallow
Version
library | version |
---|---|
enzyme | 3.10.0 |
react | 16.8.6 |
react-dom | 6.8.6 |
react-test-renderer | |
adapter (below) |
Adapter
- enzyme-adapter-react-16
ParentComponentWIthSuspense.js
const OtherComponent = React.lazy(() => import('src/main/js/OtherComponent'));```
Render()
```jsx
return (
<div>
<React.Suspense fallback={<Spinner />}>
<OtherComponent here some props/>
</React.Suspense>
</div>
And this is tests
let shallowInitialComponent = async () => {
const wrapper = shallow(<ParentComponentWIthSuspense {...props} />);
await waitNextTick();
wrapper.update();
return wrapper;
};
it("Should render", async () => {
const expectedProps = {
title: "Some title",
desc: "Some cool desc",
.....// others
};
const wrapper = await shallowInitialComponent();
Object.values(expectedProps).forEach((item) => {
expect(wrapper.find("OtherComponent").prop(item)).toBe(expectedProps[item]);
});
});
The interesting thing. That it see Suspense. I mean if i will use standard import instead of lazy. The tests are passed… It is weird…
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
React suspense Error: Method “props” is meant to be run on 1 ...
I updated react and test libraries today . App works fine, lazy loading etc.. but my tests are failing.. ... Error: Method “props”...
Read more >Jest/Enzyme Error: "Method 'setState' is only meant to run on a ...
The problem is componentDidMount isn't testable and doesn't expose a promise. ... applicationsOfCandidate(candidateId), this.props.
Read more >Suspense for Data Fetching (Experimental) - React
We might want to fetch based on props. The answer to this is we want to start fetching in the event handlers instead....
Read more >enzymejs/enzyme - Gitter
Error : This method is only meant to be run on single node. 0 found instead. ... toBeFalsy(); // This fails expect(button.props().disabled).toBeFalsy();.
Read more >Continuous integration for React applications using Jest and ...
A good starting point is adding a snapshot test to ensure that the component renders the expected output, given the required props.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In your component file, you should change:
to:
and then in your tests, you’d need to
import { OtherComponent } from 'wherever';
, and then you can do.find(OtherComponent)
.If that’s still not working, a repro repo would be most helpful.
react adapter 1.14.0 .debug will show you tomorrow. Thanks