
ReactJS
Learn to render and test React components.
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();
});test('renders with props', () => {
render(<Greeting name="Alice" />);
expect(screen.getByText('Hello, Alice')).toBeInTheDocument();
});test('matches snapshot', () => {
const { container } = render(<UserCard user={{ id: 1, name: 'Alice' }} />);
expect(container).toMatchSnapshot();
});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();
});Resources
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