๐Ÿงช Jest Unit Testing

Testing React Components with Jest

What is Jest?

Jest is a JavaScript testing framework developed by Facebook. It works seamlessly with React and provides a complete testing solution with zero configuration.

๐Ÿ’ป Basic Test

// sum.js
export function sum(a, b) {
  return a + b;
}

// sum.test.js
import { sum } from './sum';

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

test('adds negative numbers', () => {
  expect(sum(-1, -2)).toBe(-3);
});

๐ŸŽฏ Key Takeaways