79320717

Date: 2024-12-31 19:59:16
Score: 1.5
Natty:
Report link

Use a custom text match function that only matches visible text.

function matchVisible(text) {
  return (content, element) => content.startsWith(text) && element.getAttribute('aria-hidden') !== 'true';
}

test('everything is fine', () => {
  render(<MyApp />);
  const error = screen.queryByText(matchVisible('flagrant error'));
  expect(error).toBeNull();
});

Reference: https://github.com/testing-library/dom-testing-library/issues/929#issuecomment-1571823720

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: nupanick