Skip to content

queryByTestId, getByTestId use partial case-insensitive text match by default, which is unexpected #8

Closed
@sompylasar

Description

@sompylasar
  • dom-testing-library version: 1.1.0
  • node version: N/A
  • npm (or yarn) version: N/A

Relevant code or config

import { getByTestId } from "dom-testing-library";

document.getElementById("test").innerHTML = `
<div data-testid="supertest-123"></div>
`;

document.getElementById("output").innerHTML = `
${getByTestId(document, "tEsT")
  .outerHTML.replace(/</g, "&lt;")
  .replace(/>/g, "&gt;")}
`;

What you did:

  1. Added an element with data-testid="supertest-123" to an empty DOM.
  2. Queried the DOM via getByTestId by string "tEsT".

What happened:

The element with data-testid="supertest-123" was found.

Reproduction repository:

https://codesandbox.io/s/pwrpl1yy9x?module=%2Fsrc%2Findex.js

Problem description:

The current behavior is unexpected, the identifiers aren't supposed to be matched partially and case-insensitively.

Suggested solution:

Use case-sensitive full-string match in queryByTestId, getByTestId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions