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(); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter