I'm trying to set up Jest for LWC. I have looked at the documentation and I have looked at the LWC website. Both of them refer to different packages for Jest installation. Which one should I use? and why?
1 Answer
As per my understanding after reading the docs,
sfdx-lwc-jest
- sfdx-lwc-jest works in Salesforce DX projects only.
- sfdx-lwc-jest, sets up all the necessary Jest configurations for a Salesforce DX project.
lwc/jest-preset
According to npm, Tools to assist with testing Lightning Web Components (LWC) with Jest. This project provides 2 services: preset Jest configuration for testing Lightning web components, and stubs for common external libraries used in Lightning web components.
After reading this Blog, @salesforce/lwc-jest is wrapper command of @lwc/jest-preset @lwc/module-resolver @lwc/compiler @lwc/engine .