1// JEST UNIT TESTING
2
3// INSTALL
4`yarn add --dev jest`
5
6// FUNCTION TO UNIT TEST
7function sum(a, b) {
8 return a + b;
9}
10module.exports = sum;
11// sum.js
12
13// JEST SUM TEST
14const sum = require('./sum');
15
16test('adds 1 + 2 to equal 3', () => {
17 expect(sum(1, 2)).toBe(3);
18});
19// sum.test.js
20
21// ADD TEST SCRIPT TO PACKAGE.JSON
22{
23 "scripts": {
24 "test": "jest"
25 }
26}
27// package.json
28
29`yarn test`
30// PASS ./sum.test.js
31// ✓ adds 1 + 2 to equal 3 (5ms)