Skip to content

Commit 9792568

Browse files
author
Kent C. Dodds
committed
fix(textMatch): if the textToMatch is not a string then it wont match
1 parent e9b603d commit 9792568

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/__tests__/element-queries.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ test('totally empty label', () => {
7676

7777
test('get element by its alt text', () => {
7878
const {getByAltText} = render(
79-
<img alt="finding nemo poster" src="/finding-nemo.png" />,
79+
<div>
80+
<input data-info="no alt here" />
81+
<img alt="finding nemo poster" src="/finding-nemo.png" />
82+
</div>,
8083
)
8184
expect(getByAltText(/fin.*nem.*poster$/i).src).toBe('/finding-nemo.png')
8285
})

src/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//eslint-disable-next-line import/prefer-default-export
22
export function matches(textToMatch, node, matcher) {
3+
if (typeof textToMatch !== 'string') {
4+
return false
5+
}
36
if (typeof matcher === 'string') {
47
return textToMatch.toLowerCase().includes(matcher.toLowerCase())
58
} else if (typeof matcher === 'function') {

0 commit comments

Comments
 (0)