sfdx-lwc-jest and its dependencies into each Salesforce DX project.
sfdx-lwc-jest works in Salesforce DX projects only.
sfdx-lwc-jest, install Node.js and npm.
This page lists two releases of Node.js. We recommend using the “LTS” (Long-Term Support) version, rather than the “Current” version.
When you install Node.js, npm also installs. You may need to update npm though, so visit the npm website for instructions.
The simplest way to install Jest and its dependencies is to run the Salesforce CLI command
sf force lightning lwc test setup. Run the command from the top-level directory of each Salesforce DX project. This command creates the necessary configuration files and installs the
sfdx-lwc-jest package for you.
If you work in an environment where you can’t use the Salesforce CLI, you can set up your test dependencies yourself.
sfdx-lwc-jest and its dependencies, run these commands once from the top directory of each Salesforce DX project.
By default, an SFDX project includes these script entries in the
scripts block of its
package.json file. If your project’s file doesn’t include them, add them.