Ojasa Mirai

Ojasa Mirai

ReactJS

Loading...

Learning Level

๐ŸŸข Beginner๐Ÿ”ต Advanced
๐Ÿงช Testing Basics๐ŸŽจ Rendering Components๐Ÿ” Querying Elements๐Ÿ‘† Simulating Events๐Ÿงช Async Testing๐ŸŽญ Mocking๐Ÿงช Test Organization๐Ÿงช Testing Best Practices
Reactjs/Testing/Testing Basics

๐Ÿงช Jest Testing Basics

Jest is a zero-config testing framework for JavaScript and React.

Your First Test

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

Test Structure

describe('Calculator', () => {
  test('adds numbers', () => {
    expect(add(1, 2)).toBe(3);
  });

  test('subtracts numbers', () => {
    expect(subtract(5, 3)).toBe(2);
  });
});

Common Matchers

expect(value).toBe(5);              // Exact match
expect(value).toEqual({ a: 1 });    // Deep equality
expect(value).toBeTruthy();         // Truthy
expect(value).toContain(2);         // Array contains
expect(text).toMatch(/jest/i);      // Regex match

Running Jest

npm test                    # Run all tests
npm test -- --coverage      # With coverage
npm test -- --watch         # Watch mode

โœ… Key Takeaways

  • Jest is **zero-config** and works out of the box
  • Use **test()** to write test cases
  • Use **expect()** with **matchers** for assertions
  • **describe()** groups related tests

Resources

Python Docs

Ojasa Mirai

Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.

Learn Deep โ€ข Build Real โ€ข Verify Skills โ€ข Launch Forward

Courses

PythonFastapiReactJSCloud

ยฉ 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn