Loadable-components: Need help for my unit test with load

Created on 27 Jan 2020  路  4Comments  路  Source: gregberge/loadable-components

馃挰 Questions and Help

I have a wrapped loadableComponent inside another stateless component, I want to check if the loadable it's already rendered, previously with react-loadable, we didn't need to worry about this since with the help of preloadAll() we achieved it, but not sure how to force the load of the component before my assertion happen.

const wrapper = mount(<Wrapper name="test" `/>);

expect(wrapper.find('svg')).toHaveLength(1); // not loaded yet
const Wrapper = (props) => {
   const MyLoadable = loadable(() => import('./MyOtherComp');

   return (<Errors><MyLoadable /></Errors>);
}

Most helpful comment

With react-testing-library you should be able to wait for the component to be ready.

All 4 comments

Hey @yanv1991 :wave:,
Thank you for opening an issue. We'll get back to you as soon as we can.
Please, consider supporting us on Open Collective. We give a special attention to issues opened by backers.
If you use Loadable at work, you can also ask your company to sponsor us :heart:.

preloadAll does not exist. You have to wait for the element to be present, like you do in real.

@gregberge that's my goal, but not sure how to achieve that with loadable-component, any suggestions ? I can do that if I have access to my loadable component directly in my test using load but in this case my component is wrapped inside another stateless . Thank you in advance .

With react-testing-library you should be able to wait for the component to be ready.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lauterry picture lauterry  路  6Comments

gregberge picture gregberge  路  6Comments

luishdz1010 picture luishdz1010  路  6Comments

zetekla picture zetekla  路  5Comments

bitttttten picture bitttttten  路  8Comments