npm init
package.json edit/tambahkan :
"type" : "commonjs" -> "type" : "module"
"scripts": {
"test": "jest" or "./node_modules/.bin/jest"
}
depedency :
npm install jest --save-dev,
npm install @types/jest --save-dev
npm install ts-jest --save-dev
npm install @babel/preset-env --save-dev
npm install @babel/preset-typescript --save-dev
npm install @babel/plugin-transform-runtime --save-dev
or
npm i
run windows :
node_modules/.bin/jest
run unix (linux/mac) :
./node_modules/.bin/jest
run :
npm run test
easy run (using npx , for auto detect node_modules/.bin/) :
npx jest
Note :
- Command Line untuk run test spesific file
./node_modules/.bin/jest --runTestsByPath test/sum.test.ts or npx jest --runTestsByPath test/sum.test.ts or npx jest test/sum.test.ts
- Command Line untuk run test spesific file by function test name
npx jest --testNamePattern "test sum function 2"
or
npx jest --t "test sum function 2"
or
(optional) visual studio code , install extention "Jest" supaya bs test speisifc file test atau kelik kanan function
(supaya bs running speisifc by function name) , dll
"run test at cursor"
(test 1 file)
"run test at current file"
"TIME > KNOWLEDGE > MONEY". #2023_3_DIGIT_MOTIVATION
🔗 https://babeljs.io/repl (javascript module to javascript commonjs)
🔗 https://www.javainuse.com/js2ts (javascript to typescrypt)
🔗 https://jestjs.io/docs/getting-started#using-typescript
🔗 https://github.com/EKI-INDRADI/eki-latihan-nodejs-unit-test-javascript-module
🔗 https://www.youtube.com/watch?v=UNaYui-EG_8&ab_channel=ProgrammerZamanNow
🔗 https://docs.google.com/presentation/d/1f3yg05_bX0HFybD9qBCqPq64l8Tiu-f4iWhCQBMG_eM/edit
🔗 https://github.com/ProgrammerZamanNow/belajar-nodejs-unit-test