I am trying to test dynamic import in nextjs version 10.2.3, i tried using jest-next-dynamic library which avoid throwing error
TypeError: require.resolveWeak
but when i debug the component in jest test case i get below output and cannot get real component that should be loaded
<ForwardRef(LoadableComponent) .../>
My test case
it('should render Image component from next/Image', () => {
await preloadAll();
defaultProps = getDefaultProps(imgSrcFromAssetsLocation);
const ContainerImage = shallow(<ContainerImage { ...defaultProps } />);
console.log(ContainerImage.debug());
expect(ContainerImage.prop('layout')).toEqual('responsive');
});
After some time i figured out we need to wait for dynamic element to load in test case using waitFor or something similar, documentation of "jest-next-dynamic" does not include this, i found this from below github repo github repo with example