Jest error: cannot find module ‘lightning/alert’ from’ ‘.../newAccount.test.js’. What does this error mean?

If I am trying to run the test for LWC, I am getting this error. I also tried to mock the missing function but failed to find something like that in the repo. Can anyone please help me find the solution to this problem?

Answered by Bruce Benedict

This problem that just cannot find modules is quite common if not much. If you do not find any stub provided for a standard module in the sfdx-lwc-jest repo, you can create a stub. Lwc recipes provide an example for an alert, which can help to create the stub. Also, you can update the jest.config.js file. It can point to the import in the stub.


Your Answer

Interviews

Parent Categories