Skip to content

Commit fef1f8a

Browse files
mvolkmannKent C. Dodds
authored andcommitted
fx: text to match fix (#24)
* made improvement to matches function proposed by KCD and added a test case * added myself as a contributor
1 parent 200ee31 commit fef1f8a

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@
137137
"doc",
138138
"test"
139139
]
140+
},
141+
{
142+
"login": "mvolkmann",
143+
"name": "Mark Volkmann",
144+
"avatar_url": "https://avatars0.githubusercontent.com/u/79312?v=4",
145+
"profile": "http://ociweb.com/mark/",
146+
"contributions": [
147+
"bug",
148+
"code"
149+
]
140150
}
141151
]
142152
}

README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[![downloads][downloads-badge]][npmtrends]
1717
[![MIT License][license-badge]][license]
1818

19-
[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors)
19+
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors)
2020
[![PRs Welcome][prs-badge]][prs]
2121
[![Code of Conduct][coc-badge]][coc]
2222

@@ -40,23 +40,22 @@ to maintain.
4040
## Table of Contents
4141

4242
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
43-
4443
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
4544

46-
* [Installation](#installation)
47-
* [Usage](#usage)
48-
* [Custom matchers](#custom-matchers)
49-
* [`toBeInTheDOM`](#tobeinthedom)
50-
* [`toHaveTextContent`](#tohavetextcontent)
51-
* [`toHaveAttribute`](#tohaveattribute)
52-
* [`toHaveClass`](#tohaveclass)
53-
* [`toHaveStyle`](#tohavestyle)
54-
* [`toBeVisible`](#tobevisible)
55-
* [Inspiration](#inspiration)
56-
* [Other Solutions](#other-solutions)
57-
* [Guiding Principles](#guiding-principles)
58-
* [Contributors](#contributors)
59-
* [LICENSE](#license)
45+
- [Installation](#installation)
46+
- [Usage](#usage)
47+
- [Custom matchers](#custom-matchers)
48+
- [`toBeInTheDOM`](#tobeinthedom)
49+
- [`toHaveTextContent`](#tohavetextcontent)
50+
- [`toHaveAttribute`](#tohaveattribute)
51+
- [`toHaveClass`](#tohaveclass)
52+
- [`toHaveStyle`](#tohavestyle)
53+
- [`toBeVisible`](#tobevisible)
54+
- [Inspiration](#inspiration)
55+
- [Other Solutions](#other-solutions)
56+
- [Guiding Principles](#guiding-principles)
57+
- [Contributors](#contributors)
58+
- [LICENSE](#license)
6059

6160
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
6261

@@ -205,11 +204,11 @@ This allows you to check if an element is currently visible to the user.
205204

206205
An element is visible if **all** the following conditions are met:
207206

208-
* it does not have its css property `display` set to `none`
209-
* it does not have its css property `visibility` set to either `hidden` or
207+
- it does not have its css property `display` set to `none`
208+
- it does not have its css property `visibility` set to either `hidden` or
210209
`collapse`
211-
* it does not have its css property `opacity` set to `0`
212-
* its parent element is also visible (and so on up to the top of the DOM tree)
210+
- it does not have its css property `opacity` set to `0`
211+
- its parent element is also visible (and so on up to the top of the DOM tree)
213212

214213
```javascript
215214
// add the custom expect matchers once
@@ -262,11 +261,10 @@ more verbose, less clear in its intent, and/or harder to read.
262261
Thanks goes to these people ([emoji key][emojis]):
263262

264263
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
265-
266264
<!-- prettier-ignore -->
267265
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=kentcdodds "Code") [📖](https://github.com/gnapse/jest-dom/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/gnapse/jest-dom/commits?author=kentcdodds "Tests") | [<img src="https://avatars1.githubusercontent.com/u/2430381?v=4" width="100px;"/><br /><sub><b>Ryan Castner</b></sub>](http://audiolion.github.io)<br />[📖](https://github.com/gnapse/jest-dom/commits?author=audiolion "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/8008023?v=4" width="100px;"/><br /><sub><b>Daniel Sandiego</b></sub>](https://www.dnlsandiego.com)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=dnlsandiego "Code") | [<img src="https://avatars2.githubusercontent.com/u/12592677?v=4" width="100px;"/><br /><sub><b>Paweł Mikołajczyk</b></sub>](https://github.com/Miklet)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=Miklet "Code") | [<img src="https://avatars3.githubusercontent.com/u/464978?v=4" width="100px;"/><br /><sub><b>Alejandro Ñáñez Ortiz</b></sub>](http://co.linkedin.com/in/alejandronanez/)<br />[📖](https://github.com/gnapse/jest-dom/commits?author=alejandronanez "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1402095?v=4" width="100px;"/><br /><sub><b>Matt Parrish</b></sub>](https://github.com/pbomb)<br />[🐛](https://github.com/gnapse/jest-dom/issues?q=author%3Apbomb "Bug reports") [💻](https://github.com/gnapse/jest-dom/commits?author=pbomb "Code") [📖](https://github.com/gnapse/jest-dom/commits?author=pbomb "Documentation") [⚠️](https://github.com/gnapse/jest-dom/commits?author=pbomb "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1288694?v=4" width="100px;"/><br /><sub><b>Justin Hall</b></sub>](https://github.com/wKovacs64)<br />[📦](#platform-wKovacs64 "Packaging/porting to new platform") |
268266
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
269-
| [<img src="https://avatars1.githubusercontent.com/u/1241511?s=460&v=4" width="100px;"/><br /><sub><b>Anto Aravinth</b></sub>](https://github.com/antoaravinth)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Code") [⚠️](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Tests") [📖](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3462296?v=4" width="100px;"/><br /><sub><b>Jonah Moses</b></sub>](https://github.com/JonahMoses)<br />[📖](https://github.com/gnapse/jest-dom/commits?author=JonahMoses "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Code") [⚠️](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Tests") [📖](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[🐛](https://github.com/gnapse/jest-dom/issues?q=author%3Asompylasar "Bug reports") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/4439618?v=4" width="100px;"/><br /><sub><b>Jesse Day</b></sub>](https://github.com/jday3)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=jday3 "Code") | [<img src="https://avatars0.githubusercontent.com/u/15199?v=4" width="100px;"/><br /><sub><b>Ernesto García</b></sub>](http://gnapse.github.io)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=gnapse "Code") [📖](https://github.com/gnapse/jest-dom/commits?author=gnapse "Documentation") [⚠️](https://github.com/gnapse/jest-dom/commits?author=gnapse "Tests") |
267+
| [<img src="https://avatars1.githubusercontent.com/u/1241511?s=460&v=4" width="100px;"/><br /><sub><b>Anto Aravinth</b></sub>](https://github.com/antoaravinth)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Code") [⚠️](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Tests") [📖](https://github.com/gnapse/jest-dom/commits?author=antoaravinth "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/3462296?v=4" width="100px;"/><br /><sub><b>Jonah Moses</b></sub>](https://github.com/JonahMoses)<br />[📖](https://github.com/gnapse/jest-dom/commits?author=JonahMoses "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Code") [⚠️](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Tests") [📖](https://github.com/gnapse/jest-dom/commits?author=lgandecki "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[🐛](https://github.com/gnapse/jest-dom/issues?q=author%3Asompylasar "Bug reports") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/4439618?v=4" width="100px;"/><br /><sub><b>Jesse Day</b></sub>](https://github.com/jday3)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=jday3 "Code") | [<img src="https://avatars0.githubusercontent.com/u/15199?v=4" width="100px;"/><br /><sub><b>Ernesto García</b></sub>](http://gnapse.github.io)<br />[💻](https://github.com/gnapse/jest-dom/commits?author=gnapse "Code") [📖](https://github.com/gnapse/jest-dom/commits?author=gnapse "Documentation") [⚠️](https://github.com/gnapse/jest-dom/commits?author=gnapse "Tests") | [<img src="https://avatars0.githubusercontent.com/u/79312?v=4" width="100px;"/><br /><sub><b>Mark Volkmann</b></sub>](http://ociweb.com/mark/)<br />[🐛](https://github.com/gnapse/jest-dom/issues?q=author%3Amvolkmann "Bug reports") [💻](https://github.com/gnapse/jest-dom/commits?author=mvolkmann "Code") |
270268

271269
<!-- ALL-CONTRIBUTORS-LIST:END -->
272270

src/__tests__/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ test('.toHaveTextContent', () => {
2626
const {queryByTestId} = render(`<span data-testid="count-value">2</span>`)
2727

2828
expect(queryByTestId('count-value')).toHaveTextContent('2')
29+
expect(queryByTestId('count-value')).toHaveTextContent(2)
2930
expect(queryByTestId('count-value')).toHaveTextContent(/2/)
3031
expect(queryByTestId('count-value')).not.toHaveTextContent('21')
3132
expect(() =>

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ function getMessage(
5454
}
5555

5656
function matches(textToMatch, node, matcher) {
57-
if (typeof matcher === 'string') {
58-
return textToMatch.toLowerCase().includes(matcher.toLowerCase())
59-
} else {
57+
if (matcher instanceof RegExp) {
6058
return matcher.test(textToMatch)
59+
} else {
60+
return textToMatch.toLowerCase().includes(String(matcher).toLowerCase())
6161
}
6262
}
6363

0 commit comments

Comments
 (0)