From 5e8858a70d1f993507aa91b6eff86afbbdd511b9 Mon Sep 17 00:00:00 2001 From: Jeff Payan Date: Thu, 26 Sep 2019 11:23:08 -0700 Subject: [PATCH 1/2] fail the match if the textToMatch is boolean --- src/__tests__/misc.js | 13 ++++++++++++- src/lib/matches.js | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/__tests__/misc.js b/src/__tests__/misc.js index 91c2ea4..46700a7 100644 --- a/src/__tests__/misc.js +++ b/src/__tests__/misc.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Button, Picker, Switch, Text, View } from 'react-native'; +import { Button, Picker, Switch, Text, View, TextInput } from 'react-native'; import { toMatchDiffSnapshot } from 'snapshot-diff'; import { cleanup, fireEvent, render } from '../'; @@ -89,3 +89,14 @@ test('it finds by value={false}', () => { getByDisplayValue(false); }); + +test("it finds by value={'hey'} when another a Switch with value={true} is present", () => { + const { getByDisplayValue } = render( + + + + , + ); + + getByDisplayValue('hey'); +}); diff --git a/src/lib/matches.js b/src/lib/matches.js index c017338..5eefdea 100644 --- a/src/lib/matches.js +++ b/src/lib/matches.js @@ -1,5 +1,5 @@ function fuzzyMatches(textToMatch, node, matcher, normalizer) { - if (typeof matcher === 'boolean') { + if (typeof matcher === 'boolean' || typeof textToMatch === 'boolean') { return textToMatch == matcher; } @@ -18,7 +18,7 @@ function fuzzyMatches(textToMatch, node, matcher, normalizer) { } function matches(textToMatch, node, matcher, normalizer) { - if (typeof matcher === 'boolean') { + if (typeof matcher === 'boolean' || typeof textToMatch === 'boolean') { return textToMatch === matcher; } From de7502d5d06e6318b8c1f3496b3b8fa21e3783c4 Mon Sep 17 00:00:00 2001 From: Jeff Payan Date: Thu, 26 Sep 2019 11:28:29 -0700 Subject: [PATCH 2/2] Add a test for picker & switch --- src/__tests__/misc.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/__tests__/misc.js b/src/__tests__/misc.js index 46700a7..cc59f72 100644 --- a/src/__tests__/misc.js +++ b/src/__tests__/misc.js @@ -100,3 +100,17 @@ test("it finds by value={'hey'} when another a Switch with value={ getByDisplayValue('hey'); }); + +test("it finds by value={'java'} when another a Switch with value={true} is present", () => { + const { getByDisplayValue } = render( + + + setValue(itemValue)}> + + + + , + ); + + getByDisplayValue('java'); +});