Skip to content

Readme: the example of getByText is not accurate #122

@ruffle1986

Description

@ruffle1986

Before getting started, let me say thank you for all the hard work to make devs` life easier with testing! Well done! 🍻

Problem description:

The example of getByText is incorrect and misleading in the readme.

It says running the following script would produce the result commented out above the script.

// <a href="/about">About ℹ️</a>
const aboutAnchorNode = getByText(container, 'about')

Since options.exact is true by default, it won't find the anchor element unless we change the code a bit (see the Suggested solution: section).

Suggested solution:

I see three options here to solve this:

A:

// <a href="/about">About ℹ️</a>
const aboutAnchorNode = getByText(container, 'About ℹ️')

B:

// <a href="/about">About ℹ️</a>
const aboutAnchorNode = getByText(container, 'about', {
  exact: false
})

C:

// <a href="/about">About ℹ️</a>
const aboutAnchorNode = getByText(container, /about/i)

Let me know which one is preferred and I'll open a PR on this.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions