React Testing Library - possible to render page in browser

Viewed 605

I'm testing a UI with the React Testing Library. Wondering if there is any way (including incorporating a separate package) to render the page being created by a test in my browser as I run the test. I'm basically trying to accomplish what happens with Ruby's Capybara gem's save_and_open_page function within my React tests. Is it possible?

1 Answers

You can render a component in the browser by using the testing playground:

import { screen } from "@testing-library/react"

render(<MyComponent />)

// log entire document to testing-playground
screen.logTestingPlaygroundURL()
// log a single element
screen.logTestingPlaygroundURL(screen.getByText('test'))
Related