Set Up the Project:
npm init -y
Install Dependencies:
npm install typescript jest ts-jest @types/jest --save-dev
Create a tsconfig.json:
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"strict": true,
"outDir": "./dist",
"esModuleInterop": true
},
"include": ["src/merge.ts", "test/merge.test.ts"]
}
Create a jest.config.js:
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
Add the test script in package.json:
"scripts": {
"test": "jest"
}
Execute the tests:
npm test