const sum = (num1, num2) => {
return num1 + num2
}
npm i jest
// Inside of sum.test.jstest('Hello World!', () => {});// Output
// npm test
PASS test/math.test.js✓ Hello World (1 ms)Test Suites: 1 passed, 1 totalTests: 1 passed, 1 totalSnapshots: 0 totalTime: 1.509 sRan all test suites related to changed files.
const sum = require('<path to your sum file >')test('Should return the sum of two numbers', () => {
const total = sum(5,10);
expect(total).toBe(15);
})
✓ Should return the sum of two numbers (4 ms)Test Suites: 1 passed, 1 totalTests:       1 passed, 1 totalSnapshots:   0 totalTime:        0.65 sRan all test suites related to changed files.
✕ Should return the sum of two numbers (5 ms)● Should return the sum of two numbersexpect(received).toBe(expected) // Object.is equalityExpected: 15Received: 1026 | test('Should return the sum of two numbers', () => {27 |   const total = sumOfTwo(5,10);> 28 |   expect(total).toBe(15)|                 ^at Object.<anonymous> (test/math.test.js:28:17)Test Suites: 1 failed, 1 totalTests:       1 failed, 1 totalSnapshots:   0 totalTime:        0.728 s, estimated 1 sRan all test suites related to changed files.

Software Engineer based out of NYC. Learning more about programming everyday 👍

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store