Jest is JavaScript test framework which is less configuration.
This article describes how to setup Jest with TypeScript.
🎳 Install libraries
yarn add --dev jest ts-jest @types/jest |
🏀 Configure Jest
Modify package.json
to add run test configuration
.
(If you want to run test sequentially, please use jest --runInBand
.)
"scripts": { |
Create jest.config.js
file for configuring Jest.
module.exports = { |
🐰 Setup for all test
Create ./__tests__/setup.ts
file for putting common configuration.
(e.g. clean up after all tests have run or setuping/closing DB)
// Example |
🎂 Write tests
Create a ./src/sum.ts
function file.
const sum = (a, b) => { |
After create a file which you want to write test, add ./__tests__/specs/sum.ts
test file.
import { sum } from "../../../src/sum.ts"; |
Run the test.
yarn test |
👽 [Appendix] Unit test with supertest
supertest suports unit test for Express.js App.
Installation
yarn add supertest # npm install supertest --save-dev |
How to use
import * as request from "supertest"; |
If I want to use create sample data, I needs to write the following things:
let user; |
🐝 References
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!