https://github.com/arnosolo/template1-express-ts
- Install jest
npm i supertest jest ts-jest @types/jest @types/supertest -D- Add
jest.config.jsfile
npx ts-jest config:init- Rename
jest.config.jsasjest.config.cjs
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/**/*.test.ts'], // Test all files end with .test.ts
verbose: true, // Print log of every test
forceExit: true, // Always force exit test
};- Add test file
src/__tests__/app.test.ts
import request from 'supertest'
describe('give a username and password', () => {
test('should return true', async () => {
expect(true).toBe(true)
})
})- Add test cmd in
package.json
"test": "jest"- Run test
npm run test