Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 55c9716

Browse files
jeffreyffsbcarroll22
authored andcommitted
fix(matcher): handle cases when values don't match types (#62)
* fail the match if the textToMatch is boolean * Add a test for picker & switch
1 parent a72fb3f commit 55c9716

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/__tests__/misc.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Button, Picker, Switch, Text, View } from 'react-native';
2+
import { Button, Picker, Switch, Text, View, TextInput } from 'react-native';
33
import { toMatchDiffSnapshot } from 'snapshot-diff';
44

55
import { cleanup, fireEvent, render } from '../';
@@ -89,3 +89,28 @@ test('it finds <Switch /> by value={false}', () => {
8989

9090
getByDisplayValue(false);
9191
});
92+
93+
test("it finds <TextInput /> by value={'hey'} when another a Switch with value={true} is present", () => {
94+
const { getByDisplayValue } = render(
95+
<View>
96+
<Switch value={true} />
97+
<TextInput value={'hey'} />
98+
</View>,
99+
);
100+
101+
getByDisplayValue('hey');
102+
});
103+
104+
test("it finds <Picker /> by value={'java'} when another a Switch with value={true} is present", () => {
105+
const { getByDisplayValue } = render(
106+
<View>
107+
<Switch value={true} />
108+
<Picker selectedValue={'java'} onValueChange={itemValue => setValue(itemValue)}>
109+
<Picker.Item label="Java" value="java" />
110+
<Picker.Item label="JavaScript" value="js" />
111+
</Picker>
112+
</View>,
113+
);
114+
115+
getByDisplayValue('java');
116+
});

src/lib/matches.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function fuzzyMatches(textToMatch, node, matcher, normalizer) {
2-
if (typeof matcher === 'boolean') {
2+
if (typeof matcher === 'boolean' || typeof textToMatch === 'boolean') {
33
return textToMatch == matcher;
44
}
55

@@ -18,7 +18,7 @@ function fuzzyMatches(textToMatch, node, matcher, normalizer) {
1818
}
1919

2020
function matches(textToMatch, node, matcher, normalizer) {
21-
if (typeof matcher === 'boolean') {
21+
if (typeof matcher === 'boolean' || typeof textToMatch === 'boolean') {
2222
return textToMatch === matcher;
2323
}
2424

0 commit comments

Comments
 (0)