on-internet
← Community

How to test Reac Lazy inside an object

Stack Overflow ·

At the project I'm working on, there's a few named exports like the object below: export const object = { component: React.lazy(() => import('some-component')) } (They have more properties but I'll just show this one for brevity) The issue When I try to test it using Jest, I can't test inside React.lazy: I tried mocking React.lazy with no success: jest.mock('react', () => ({ lazy: () => { return 'lazy' }, })) describe('Auth route object', () => { it('', () => { expect(auth).toBeDefined() expect(auth[0].component).toBe('lazy') }) }) This returns passed but it keeps complaining about coverage. H

Comments

Sign in or sign up to comment and upvote.

No comments yet.