I'm trying to unit test my LWC which has another custom component as child. I tried to use the steps describe in this post :
import { createElement } from 'lwc';
import EfxProjectReport from 'c/efxProjectReport';
describe('c-efx-project-report', () => {
jest.mock(
'./mocks/tsrWhen',
() => {
return {
default: jest.fn()
};
},
{ virtual: true }
);
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});
it('TODO: test case generated by CLI command, please fill in test logic', () => {
const element = createElement('c-efx-project-report', {
is: EfxProjectReport
});
document.body.appendChild(element);
expect(1).toBe(2);
});
});
With the following directory layout :
efxProjectReport
+ __tests__
++ efxProjectReport.test.js
++ mocks
+++ tsrWhen
++++ tsrWhen.html
++++ tsrWhen.js
+ efxProjectReport.css
+ efxProjectReport.html
+ efxProjectReport.js
+ efxProjectReportConfig.js
And I still get the following error when running my tests ::
Cannot find module 'c/tsrWhen' from 'efxProjectReport.html'
Any clue on how to proceed to mock custom child components ?