Netia Ingram
Netia Ingram

Reputation: 101

React Testing Library - possible to render page in browser

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

Answers (1)

Molten Ice
Molten Ice

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

Related Questions