From 979256835c49fdaf2576d116fd4a530eac8f7922 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Thu, 29 Mar 2018 17:29:48 -0600 Subject: [PATCH] fix(textMatch): if the textToMatch is not a string then it wont match --- src/__tests__/element-queries.js | 5 ++++- src/utils.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index 7c4d09d5..4161f3fe 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -76,7 +76,10 @@ test('totally empty label', () => { test('get element by its alt text', () => { const {getByAltText} = render( - finding nemo poster, +
+ + finding nemo poster +
, ) expect(getByAltText(/fin.*nem.*poster$/i).src).toBe('/finding-nemo.png') }) diff --git a/src/utils.js b/src/utils.js index 87ecef8b..b37542f1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,8 @@ //eslint-disable-next-line import/prefer-default-export export function matches(textToMatch, node, matcher) { + if (typeof textToMatch !== 'string') { + return false + } if (typeof matcher === 'string') { return textToMatch.toLowerCase().includes(matcher.toLowerCase()) } else if (typeof matcher === 'function') {