Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 702
Netia Ingram Avatar asked Aug 07 '26 08:08

Netia Ingram


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'))
like image 133
Molten Ice Avatar answered Aug 11 '26 09:08

Molten Ice