Reputation: 101
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?
Upvotes: 7
Views: 5992
Reputation: 2903
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'))
Upvotes: 5