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/Rendering Components

๐ŸŽจ Rendering Components with Jest

Learn to render and test React components.

Basic Render

import { render, screen } from '@testing-library/react';
import { Button } from './Button';

test('renders button', () => {
  render(<Button>Click me</Button>);
  expect(screen.getByText('Click me')).toBeInTheDocument();
});

Testing with Props

test('renders with props', () => {
  render(<Greeting name="Alice" />);
  expect(screen.getByText('Hello, Alice')).toBeInTheDocument();
});

Snapshot Testing

test('matches snapshot', () => {
  const { container } = render(<UserCard user={{ id: 1, name: 'Alice' }} />);
  expect(container).toMatchSnapshot();
});

Conditional Rendering

test('shows loading state', () => {
  render(<DataLoader isLoading={true} />);
  expect(screen.getByText('Loading...')).toBeInTheDocument();
});

test('shows data when loaded', () => {
  render(<DataLoader isLoading={false} data={{ name: 'Alice' }} />);
  expect(screen.getByText('Alice')).toBeInTheDocument();
});

โœ… Key Takeaways

  • Use **render()** to render components
  • Access elements via **screen**
  • Test with different **props**
  • Use **snapshots** for regression testing

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