so I have a react component that uses:
const MyPage = DynamicImport({
id: 'MyPage',
loader: () => import('./pages/MyPage/MyPageWrapper'),
});
and jest complains that my test isn't covering the loader, line 22:
then this is used later on the same file:
const tabs = useMemo(
() => [
{
label: 'myPage',
url: 'myRoute',
component: MyPage,
},
...
and finally
{tabs.map(({ url, component }) => {
return <Route path={url} component={component} key={url} />;
})}
I am learning how to write unit tests and I have no clue how to cover this piece in red lines on the screenshot, I've been obviously googling and searching for an answer but I couldn't find anything useful.
This is my test file:
import React from 'react';
import { MyComponent } from '../MyComponent';
import { makeSetupComponent } from '../../../../test_utils';
const MyPage = () => ({
id: '',
loader: jest.fn(),
});
jest.mock('../pages/MyPage/MyPageWrapper', () => {
return {
MyPageWrapper: jest.fn(),
};
});
const defaultProps = {
...
};
const setup = makeSetupComponent({
props: defaultProps,
shallow: true,
component: MyComponent,
});
describe('MyComponent component', () => {
test('Renders correctly', () => {
const { component } = setup();
expect(component.exists()).toBe(true);
});
test('render MyPage', () => {
const { component } = setup({ shallow: false });
console.log('###DEBUG', component.debug());
console.log('###MyPage', MyPage);
const { loader } = MyPage();
loader();
expect(MyPage).toBeInstanceOf(Function);
expect(loader).toHaveBeenCalled();
});
});
Any help/suggestions/links/courses-that-cover-exactly-this would be highly appreciated

