Skip to content

Make the case-insensitive text matching only when TextMatch is a string. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2018

Conversation

thchia
Copy link
Contributor

@thchia thchia commented Apr 12, 2018

What:
Convert the matched text to lowercase only when TextMatch is a string.

Why:
Converting it to lowercase for all types of TextMatch breaks case sensitive RegExp matching (#21)

const Component = () => <div>HELLO World</div>

// fails to match because we are trying to match
// against 'HELLO World'.toLowerCase()
getByText(/HELLO World/)

How:
In matches.js, only convert the normalizedText to lowercase if TextMatch is a string. I think that should preserve the case-insensitive nature of matching when TextMatch is a string. I have chosen to leave the case when TextMatch is a function as case-sensitive as well, since this situation is supposed to delegate as much control back to the user.

Checklist:

  • Documentation N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes! Thank you for catching this!

@kentcdodds kentcdodds merged commit 131a20b into testing-library:master Apr 12, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 1.7.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants