Skip to content

Instantly share code, notes, and snippets.

@paigen11
Created March 28, 2020 19:38
Show Gist options
  • Save paigen11/33f07022cb425bb23be9386e4f343fa5 to your computer and use it in GitHub Desktop.
Save paigen11/33f07022cb425bb23be9386e4f343fa5 to your computer and use it in GitHub Desktop.
Sample code using screen to ID elements in the DOM instead of container or component with React Testing Library
import React from 'react';
import { screen } from '@testing-library/dom';
import { render } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import App from './App';
describe('Product Browser App', () => {
it('renders a welcome message', () => {
act(() => {
render(<App />);
});
screen.findByText('Hello world');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment