question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Lazy tests failing. Error: Method “props” is meant to be run on 1 node. 0 found instead.

See original GitHub issue

Your 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:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Jun 14, 2019

In your component file, you should change:

const OtherComponent = React.lazy(() => import('src/main/js/OtherComponent'));

to:

export const OtherComponent = React.lazy(() => import('src/main/js/OtherComponent'));

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.

1reaction
DonikaVcommented, Jun 10, 2019

react adapter 1.14.0 .debug will show you tomorrow. Thanks

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found