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

Fix matcher when values don't match types #62

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/__tests__/misc.js
Original file line number Diff line number Diff line change
@@ -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 '../';
Expand Down Expand Up @@ -89,3 +89,28 @@ test('it finds <Switch /> by value={false}', () => {

getByDisplayValue(false);
});

test("it finds <TextInput /> by value={'hey'} when another a Switch with value={true} is present", () => {
const { getByDisplayValue } = render(
<View>
<Switch value={true} />
<TextInput value={'hey'} />
</View>,
);

getByDisplayValue('hey');
});

test("it finds <Picker /> by value={'java'} when another a Switch with value={true} is present", () => {
const { getByDisplayValue } = render(
<View>
<Switch value={true} />
<Picker selectedValue={'java'} onValueChange={itemValue => setValue(itemValue)}>
<Picker.Item label="Java" value="java" />
<Picker.Item label="JavaScript" value="js" />
</Picker>
</View>,
);

getByDisplayValue('java');
});
4 changes: 2 additions & 2 deletions src/lib/matches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function fuzzyMatches(textToMatch, node, matcher, normalizer) {
if (typeof matcher === 'boolean') {
if (typeof matcher === 'boolean' || typeof textToMatch === 'boolean') {
return textToMatch == matcher;
}

Expand All @@ -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;
}

Expand Down