Jestの導入
実際のcommit
いろいろ入れる
$ npm install --save-dev typescript jest ts-jest @types/jest
ts-jest
package.jsonに追記
jest.config.jsに書いても良いが面倒なのでいったんpackage.jsonに書いている
code:package.json
{
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"transform": {
"^.+\\.ts$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
}
},
"testMatch": [
"**/test/**/*.test.ts"
],
"moduleNameMapper": {
"^app/(.+)": "<rootDir>/src/$1"
}
}
}
一つ一つの指定の意味をあまり理解していない #??
$ npm testで実行するために下記も追記
code:package.json
{
"scripts": {
"test": "jest"
},
}
tsconfig.jsonの指定はこんな感じ
code:tsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"app/*": "./*",
},
},
}
参考
TypeScript のテストを Jest (ts-jest) でやってみる - QiitaTypeScript のテストを Jest (ts-jest) でやってみる - Qiita
ほぼほぼここを参考にしている
ただし、pathの指定だけは参考にしていない