used to query for asynchronous elements which will eventually appear in the DOM-(findByX)
Sun May 22 2022 12:23:38 GMT+0000 (Coordinated Universal Time)
Saved by
@sadatakhtar
#javascript
import App from './components/App';
import { render, screen } from '@testing-library/react';
test('should show text content as Goodbye', async () => {
// Render App
render(<App />);
// Extract button node
const button = screen.getByRole('button');
// click button
userEvent.click(button);
// Wait for the text 'Goodbye!' to appear
const header = await screen.findByText('Goodbye!');
// Assert header to exist in the DOM
expect(header).toBeInTheDocument();
});
content_copyCOPY
Comments