Testing components using Jest
The page provides instructions for testing components using Jest.
Running Jest tests
CT5 uses Jest to run unit tests. Each CT5 component directory includes a tests
directory for unit tests.
To run unit tests for all components in your application, execute the command below from the root directory of your application:
$ yarn test
Debugging Jest tests
You can debug Jest tests using Google Chrome, IntelliJ IDEA, or Visual Studio Code.
Debug using Google Chrome Developer Tools
To debug application tests using Google Chrome Developer Tools, follow the steps below:
-
From the root directory of your application, run the command below:
$ yarn run test:debug
The command outputs a chrome-devtools:// URL
-
Open Google Chrome. Paste the chrome-devtools:// URL into the address bar, or navigate to chrome://inspect and select your app.
The test:debug script uses the --inspect-brk option to start the Node.js Inspector. If the test:debug script fails for you, then edit your application’s packages.json file and use the alternative definition for the test:debug script below:
|
"scripts": {
⋮
"test:debug": "node --inspect --debug-brk ./node_modules/jest-cli/bin/jest.js -i --env jest-environment-node-debug"
⋮
}
Debug using IntelliJ IDEA
To debug application tests using IntelliJ IDEA, follow the steps below:
-
Install the Node.js plugin from the JetBrains plugin repository
-
Click Run > Debug > Edit Configurations
-
Click + > Jest
-
Configure the following options:
Option Value Jest package
the path to the
node_modules/jest-cli
directory in your CT5 application directoryWorking directory
the path to your CT5 application directory
Jest options
--runInBand
Debug using Visual Studio Code
To debug application tests using Microsoft Visual Studio Code, follow the steps below:
-
Click File > Open Folder and open the directory of your CT5 application
-
Click Debug > Run Configurations
-
If prompted to select an environment, select Node.js
-
From the list of possible run configurations, select Launch Program
-
Edit the Launch Program configuration:
{ "type": "node", "request": "launch", "name": "Debug Jest tests", "program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js", "args": "--runInBand" }
-
Click Debug > Start Debugging