[Log] Jest: Getting Started
Create a project directory.
npm init -y
npm i -D jest
touch index.js
touch calc.js
Write code.
function add(a, b) {
return a + b
}
module.exports = add
Make test directory.
mkdir test
touch test/calc.test.js
Write test code.
const add = require('../calc');
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
Edit package.json.
"main": "index.js",
"scripts": {
"test": "jest"
},
Run test.
npm test