Open
Description
@testing-library/react
version: 13.3.0- Testing Framework and version:jest@27.5.1
- DOM Environment:jsdom@16.7.0 jest-environment-jsdom@^27.5.1
Using multiline text in getByText fails. Is there a workaround for this?
Failing test
const exampleText = `
hello
world
`
const textElement = screen.getByText(
exampleText.slice(0, 10),
{ exact: false }
);
console.info(textElement.textContent === exampleText); // == True
expect(screen.getByText(exampleText)).toBeInTheDocument(); // == Fail
Passing test
const exampleText = `hello world`
const textElement = screen.getByText(
exampleText.slice(0, 10),
{ exact: false }
);
console.info(textElement.textContent === exampleText); // == True
expect(screen.getByText(exampleText)).toBeInTheDocument(); // == Pass
Metadata
Metadata
Assignees
Labels
No labels