Closed amaschas closed 1 year ago
You can log roles by
test("A sample test.", () => {
const { container } = render(() => (<div>Testing</div>));
logRoles(container);
});
The result object includes other things besides the DOM.
This is working as intended. You probably want to do what Joel explained in https://github.com/testing-library/dom-testing-library/issues/1165#issuecomment-1509356454:
test("A sample test.", () => {
const { container } = render(() => (<div>Testing</div>));
logRoles(container);
});
@testing-library/dom
version: 8.17.1Relevant code or config:
What you did:
I'm trying to log the roles available in a rendered component.
What happened:
I get an error telling me that logRoles only works with
HTMLElement
and notRenderResult
.Problem description:
I'm not really sure how
logRoles
is even supposed to be used, given that it can't show me the roles available in aRenderResult
. It's actually easier to just toscreen.getByRole('foo')
at this point to find out what roles are available within your component. I think that logRoles should either just take aRenderResult
, or the documentation should explain how to use logRoles with aRenderResult
, since most users are probably just going to render their test component, and then want to see what roles they can test for.