Setting up a testing framework
We will be using Jest as our testing framework tool. It was initially developed for JavaScript, hence the name Jest. But today it works with various projects using TypeScript, React, Node.js, Angular, and so on.
First, we need to install Jest in our project using the following command:
npm install jest @types/jest ts-jest --save-dev
Similar to the previous section, we use the --save-dev attribute as this activity will only be performed during the development phase and has no effect on running the application.
Now, let’s add a folder named tests and create a configuration file named jest.config.js in the root directory of your PCF project for Jest to run its test cases. The following is the sample configuration file for Jest:
jest.config.js
module.exports = {
verbose: true,
rootDir: “.”,
testMatch: [“<rootDir>/tests/*.(spec|test).(j|t)s”],
...