Mid
From PDF
React
React.js
Assertions: Use expect() to assert the expected behavior.?
Example:
import { render, screen, fireEvent } from '@testing-library/react';
import MyComponent from './MyComponent';
test('renders the component and interacts', () => {
render(<MyComponent />);
const button = screen.getByText('Click me');
fireEvent.click(button);
expect(screen.getByText('Clicked!')).toBeInTheDocument();
});
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png