Setup JEST Testing for Salesforce LWC

Setup JEST Framework for Lightning Web Components

Before we install lwc-JEST for LWC, we need to install 2 other softwares to support.
LWC-JEST
  1. Node.js : This page may have two versions of node files. we recommend to use LTS(Long Term Support) version. Download and install it.
  2. npm:When you install Node.js, npm also installs.
Make sure you have Node and NPM installed by running simple commands to see what version of each is installed.
Node: Open command prompt and run node -v It will show verision like this: v12.14.0
NPM: Open command prompt and run npm -v It will show verision like this: 6.13.4

If Node and npm are successfully installed, then open your vs code project and follow the below steps to install lwc-jest.
Step:1
Open terminal in vs code by view --> Terminal or shortcut keys for windows (control + ~ )
vs-code-terminal

Step:2
Run npm init command to create package.json file in the project root folder. This command will ask some details you can leave blank and hit enter to finish.
lwc-jest-npm-init

Step:3
Now run following two commands one by one to install node modules.
npm install
npm install @salesforce/sfdx-lwc-jest --save-dev
lwc-jest-npm-install

Step:4
Now open the package.json file created in step no 2 and add below lines in the script block.
    "test:unit": "sfdx-lwc-jest",
    "test:unit:coverage": "sfdx-lwc-jest --coverage",
    "test:unit:watch": "sfdx-lwc-jest --watch",
    "test:unit:debug": "sfdx-lwc-jest --debug"
lwc-jest-commands
you can alos add more commands from this list sfdx-lwc-jest commands.
That's it. If you stuck anywhere follow this JEST setup document by salesforce.
 Next post we will create simple lwc components with JEST test class.

COMMENTS

Name

Android Apps,1,Apex,7,Apex Methods,1,Batch Apex,2,Chrome Add-on,1,Chrome browser,1,Coding Best Practices,2,CRM Basics,1,cURL,1,Database Query,1,Dataset,1,Dynamic Apex,3,Dynamic SOQL,1,Einstein Analytics,9,Future Apex,1,Git,1,Google Chrome,1,IDs and Urls Hacks,1,JS for LWC,5,Lightning Components,2,lightning Page,1,Lightning Web Components,14,Linux for Windows users,1,LWC,16,LWC-JEST,7,Queueable Apex,1,Redirect page,1,REGEX,1,REST API,1,Salesforce CRM,1,Salesforce Errors,1,Salesforce Handy Commands,1,Salesforce Interview Questions,14,Salesforce Lightning,1,Salesforce New Features,1,Salesforce Tasks,2,Schedule Apex,1,SLDS,4,SVG Image,3,Test Class,1,Triggers,1,uiObjectInfoApi,1,Visualforce Pages,3,Visualforce Pagination,2,VS Code,2,Wave Analytics,7,Winter Release Notes,1,workbench,1,
ltr
item
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog: Setup JEST Testing for Salesforce LWC
Setup JEST Testing for Salesforce LWC
Setup JEST Testing for Salesforce LWC ,Setup JEST Framework for Lightning Web Components,Jest framework for lwc components to test code coverage of lightning web components.
https://1.bp.blogspot.com/-rwfqkd3eCzY/Xgy4yOivm6I/AAAAAAAAAWA/YeXlJ8ibNg4LASVmgQLPZBIsQMJ50MprgCLcBGAsYHQ/s640/LWC-JEST.jpeg
https://1.bp.blogspot.com/-rwfqkd3eCzY/Xgy4yOivm6I/AAAAAAAAAWA/YeXlJ8ibNg4LASVmgQLPZBIsQMJ50MprgCLcBGAsYHQ/s72-c/LWC-JEST.jpeg
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog
https://www.swdcworld.com/2019/12/setup-jest-testing-for-salesforce-lwc.html
https://www.swdcworld.com/
https://www.swdcworld.com/
https://www.swdcworld.com/2019/12/setup-jest-testing-for-salesforce-lwc.html
true
5370056087523941001
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy