When you render
a component with the Redux Testing Library you get back a result object with numerous properties. One of those properties is debug which will log the HTML for whatever component you just rendered. It might look something like this:
const { debug } = render(<h1>Hello World</h1>);
debug(); // logs <h1>Hello World</h1>
There's also another approach to logging HTML using screen.debug, which takes an an argument any queried element. One example would be:
screen.debug(screen.getByRole("table"));
Just remember that whether you use debug()
or screen.debug()
you don't need to wrap it in a console.log()
!
Instructor: [0:00] Open up your IDE and in the products folder, create a new file called products.test.TSX. In that file, we're going to import react, and we'll also import render context test details, and we're going to import products from ./products.
[0:16] For our first test, we're going to test the products component. For this one type const {debug} = render with context products. Now type debug, followed by (). This debug utility is not something that we wrote.
[0:30] If we go into render with context, you can see that we're returning all the utils provided by the testing library react render function. One of those utils is called debug. If we open up our terminal window and type NPX.JS-- products.test.
[0:46] That filters on this and not product slice. We can see the debug will log all the HTML for a given component.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!