Mid From PDF React React.js

Assert behavior: Use expect() to check the outcome, like whether an element is?

rendered or a function is called.

Example of a simple unit test:

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

import Counter from './Counter';

test('increments counter on button click', () => {

render(<Counter />);

const button = screen.getByText('Increment');

fireEvent.click(button);

expect(screen.getByText('1')).toBeInTheDocument();

});

In this test, you:

More from React.js Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details