I have written a bunch of tests for LWC. I'm trying to run it using sfdx force:lightning:lwc:test:run but I run into:

ERROR running force:lightning:lwc:test:run: No lwc-jest executable found. Verify it is properly installed. Run "sfdx force:lightning:lwc:test:setup --help" for installation details.

I tried to install lwc-jest using @salesforce/lwc-jest looks like it's been deprecated and has been renamed to @salesforce/sfdx-lwc-jest.

Does this mean sfdx force:lightning:lwc:test:run is referencing an older module (@salesforce/lwc-jest)?

Is there a way to fix this/what am I missing here?

Note: I'm able to run tests using npm run test:unit.


I tried installing jest using sfdx force:lightning:lwc:test:setup and ran into the below issue:

ERROR running force:lightning:lwc:test:setup: npm command not found. Verify npm is properly installed and try again.

I have installed jest using:

npm install
npm install @salesforce/sfdx-lwc-jest --save-dev

NPM version - 6.4.1

NPM Path - C:\Users\UserName\AppData\Roaming\npm\node_modules

Node Version - v10.15.1

OS - Windows

  • Please mention the operating system and node version you have as it works fine on MACOSX. – Mohith Shrivastava Jun 8 at 13:38
  • I agree with @MohithShrivastava, to me, it seems that npm is not on the default path of your OS. That is why sfdx force:lightning:lwc:test:setup has failed. – Jeferson Chaves Jun 8 at 14:27
  • @MohithShrivastava NPM version 6.4.1 and OS windows. I updated my question as well. – d_k Jun 8 at 14:40
  • What about node version and also what’s your default npm path? – Mohith Shrivastava Jun 8 at 14:41
  • Hi @MohithShrivastava I have added that to the question now. – d_k Jun 8 at 15:35

You were pretty much spot on with your investigation and finding that lwc-jest has been deprecated in favor of sfdx-lwc-jest. The SFDX plugin was in fact referencing the deprecated binary.

This has just been fixed in the plugin by this PR and should be released into the main SFDX CLI via a patch release in a week or two.

| improve this answer | |
  • Thank you! @trevorBliss – d_k Jul 10 at 7:50

npm i @salesforce/sfdx-lwc-jest

This should do the trick

| improve this answer | |
  • 1
    This worked for me. Ran into the same error as the original question even with latest versions of node and npm – Avinash Jul 5 at 16:34

Either try to install using sfdx force:lightning:lwc:test:setup or if you are trying to use npm directly, you can install sfdx-lwc-jest instead of lwc-jest, see the page you referred:

This package, @salesforce/lwc-jest, has been renamed to @salesforce/sfdx-lwc-jest. Please update your projects to reference @salesforce/sfdx-lwc-jest. @salesforce/lwc-jest will continue to be updated through the Winter '20 release, then development and releases will only happen against @salesforce/sfdx-lwc-jest.

| improve this answer | |
  • I have updated my question. @jeferson chaves – d_k Jun 8 at 12:36
  • Hey, @d_k: have you removed the previous module lwc-jest? – Jeferson Chaves Jun 8 at 12:41
  • Yes, I have removed the lwc-jest module. – d_k Jun 8 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.