Jest is one of many famous testing frameworks in Typescript
Jest by default runs in CommonJS mode and doesn’t understand TypeScript imports unless we configure a transformer.
npm init -y
npx tsc --init
"rootDir": "./src",
"outDir": "./dist",
src/index.tsexport function sum(a: number, b: number) {
return a + b
}
export function multiply(a: number, b: number) {
return a * b
}
export function substract(a: number, b: number) {
return a - b
}
export function devide(a: number, b: number) {
if (b === 0) throw Error("cant devide by zero")
return a / b
}
Jest was originally made for JavaScript app testing not so compatible with Ts but still we can use it with the help of Ts-jest

npm install --save-dev ts-jest @jest/globals @types/jest
npx ts-jest config:init
update jest.config.js
import {createDefaultPreset} from "ts-jest"
const tsJestTransformCfg = createDefaultPreset().transform;
/** @type {import("jest").Config} **/
export default {
testEnvironment: "node",
preset: 'ts-jest',
transform: {
...tsJestTransformCfg,
},
};
package.json