Note: LWC test support for CI jobs is currently in early beta. It requires git as the source for a CI job to run and results are currently only included as part of a Slack notification for CI job results. Only test failures are currently reported and a CI job will still attempt to deploy metadata on LWC test failures.

Source control repository setup instructions

The current implementation of LWC tests assumes that you've set up your repo in the same way as the example project. See also

  1. Install the sfdx-lwc-jest package with npm install @salesforce/sfdx-lwc-jest.

  2. Tests must be in a __tests__ folder. The suggested way to set this up is to create a __tests__ folder in each component's folder (that is being tested). For example, if you had a teamComponent that looked like this in the file structure:

then you add your test file like so:

3. Add **/__tests__/** to .forceignore so that the tests aren't deployed to Salesforce.

4. Add the following script to the scripts section in package.json:

"test:unit": "sfdx-lwc-jest"

5. Test this works locally by checking out the repo, running npm ci and then npm run test:unit

In Gearset, to get any results, the CI job must have Slack notifications enabled. If the run errors or fails, a notification will be sent (a passed run won't notify)

Did this answer your question?