https://tecoble.techcourse.co.kr/post/2021-05-25-unit-test-vs-integration-test-vs-acceptance-test/
npm i jest
function sum(a, b) {
return a + b;
}
module.exports = sum;
//export default sum;
const a = require("./a");
test("두 수를 더합니다.", () => {
expect(a(1, 2)).toBe(3);
});
npx jest a.test.js
{
"dependencies": {
"jest": "^29.7.0"
},
"scripts": {
"test": "jest"
}
}
npm run test
function sum(a, b) {
return a + b;
}
function sumOf(numbers) {
let result = 0;
numbers.forEach((v) => (result += v));
return result;
}
exports.sum = sum;
exports.sumOf = sumOf;
// export const sumOf = () => {}
// module.exports = sum;
//export default sum;
const { sum, sumOf } = require("./a");
// import { useState } from 'react';
describe("덧셈 함수들", () => {
it("두 수의 합 구하기", () => {
expect(sum(2, 4)).toBe(3);
});
it("배열의 모든 숫자 더하기", () => {
const numbers = [1, 2, 3, 4, 5];
expect(sumOf(numbers)).toBe(15);
});
});
function sum(a, b) {
return a + b;
}
function sumOf(numbers) {
return numbers.reduce((acc, current) => acc + current, 0);
}
exports.sum = sum;
exports.sumOf = sumOf;
// export const sumOf = () => {}
// module.exports = sum;
//export default sum;