Skip to content

Allow exact match for toHaveTextContent without RegExp #712

@donaldpipowitch

Description

@donaldpipowitch

Describe the feature you'd like:

It would be nice if toHaveTextContent would allow for exact matches without the need to create a RegExp. (I personally would even prefer if this would be the default behaviour as it is safer.)

RegExp is harder to use when it comes about formatting bigger chunks of text (poor mans snapshot testing), some devs are sadly a bit scared about introducing RegExp and I saw cases like this testing-library/eslint-plugin-jest-dom#337 (comment).

Suggested implementation:

  • toHaveTextContent('Your text.', { exact: true }) (maybe this could even become a default behaviour in a new major version=

Describe alternatives you've considered:

  • toMatchTextContent('Your text.'): a new matcher

Teachability, Documentation, Adoption, Migration Strategy:

If you make it opt-in it is easy to roll out.

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