package.json
{
"devDependencies": {
"jest": "^26.4.2"
}
}
sum.js
module.exports = function sum(a, b) {
return a + b;
};
sum.test.js
const sum = require("./sum");
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
テスト実行
$ npx jest
PASS ./sum.test.js
✓ adds 1 + 2 to equal 3 (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.271 s
Ran all test suites.