Ever since starting with @testing-library for react, I'm confused by the name
attribute. It is possible to get the reference of a rendered button e. g. like this:
// <button>Button text</button>
screen.getbyRole("button", {name: /button text/gi})
In this case name referes to the textNode
inside of the button. The story around inputs is similar where name
can refer to e.g. the id
the name
or the text content.
I'm currently trying to get the reference of a button that is rendered like this:
<button
aria-label="Close"
class="css-1dliicy"
type="button"
>
Create new
<svg>...</svg>
</button>
And the button can not be found with the query:
const createNewButton = screen.getByRole('button', {
name: /Create new/gi,
});
I clearly don't seem to know what the name
property means but I can't seem to find docs on it.