Nikhil John
Write your unit tests in those files.
npm run test:watch OR
npm run test
// add.js export function add(x, y) { return x + y; }
// add.test.js import { add } from '../add'; describe ('add()', () => { it('adds two numbers', () => {
expect(add(1, 2)).toEqual(5);
});
it('doesn't add subsequent args after second', () => {
expect(add(1, 2, 3)).toEqual(add(1,2));
});
})
Should our function work, Jest will show this output when running the tests:
add()
✓ adds two numbers
✓ doesn't add subsequent args after second
// add.js
export function add(x, y) {
return x * y;
}
add() › adds two numbers expect(received).toEqual(expected) Expected value to equal: 5 Received: 6 add() ✕ adds two numbers
✓ doesn't add the third number