Is there a valid solution for this issue in latest versions of @salesforce/sfdx-lwc-jest? I implemented the below solution and still get the error:
"@salesforce/sfdx-lwc-jest": "1.1.0"
sfdx-cli: sfdx-cli/7.179.0 darwin-x64 node-v18.12.1
in process of updating to even newer lwc-jest but looking at the repo still no stubs for CloseActionScreenEvent
Ive tried the solution listed here Having issue with jest test for Lightning Quick action and CloseActionScreenEvent
with no luck still get same error cannot find module 'lightning/actions'
Best Answer
It's not in
@salesforce/sfdx-lwc-jest
, it's found in@trailheadapps/lwc-recipes
.Setting this up is pretty trivial, though not necessarily very obvious what you're supposed to do.
Starting from the linked repository above, you first will want to install
@salesforce/sfdx-lwc-jest
if you haven't yet:This installs the
config.js
referenced in the next step.You should have a file called
jest.config.js
in your project root, written as follows (note: this is in@trailheadapps/lwc-recipes/jest.config.js
):You can remove any module names you don't need. The important part here is in
moduleNameMapper
for'^lightning/actions$
. You'll notice that that this maps to a file:So, you should set up this folder structure in your project. Inside
force-app/test/jest-mocks/lightning
, create a file calledactions.js
, and place the contents of this file there.This is found in
@trailheadapps/lwc-recipes/force-app/test/jest-mocks/lightning/actions.js
.So, in summary, install
@salesforce/sfdx-lwc-jest
, configure ajest.config.js
, and copy the relevant modules from@trailheadapps/lwc-recipes/force-app/test/jest-mocks
.