Skip to content

Commit fec9c19

Browse files
committed
refactor: code review changes
1 parent d867c6e commit fec9c19

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/helpers/matchers/matchLabelText.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ function matchAccessibilityLabelledBy(
4242
return (
4343
findAll(
4444
root,
45-
(element) =>
46-
element.props?.nativeID === nativeId &&
47-
matchTextContent(element, text, options)
45+
(node) =>
46+
typeof node.type === 'string' &&
47+
node.props?.nativeID === nativeId &&
48+
matchTextContent(node, text, options)
4849
).length > 0
4950
);
5051
}

src/matches.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TextMatchOptions = {
88

99
export function matches(
1010
matcher: TextMatch,
11-
text: string | undefined,
11+
text: string,
1212
normalizer: NormalizerFn = getDefaultNormalizer(),
1313
exact: boolean = true
1414
): boolean {

src/queries/__tests__/labelText.test.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { View, Text, TouchableOpacity, TextInput } from 'react-native';
2+
import { View, Text, TextInput, TouchableOpacity } from 'react-native';
33
import { render } from '../..';
44

55
const BUTTON_LABEL = 'cool button';
@@ -173,8 +173,9 @@ test('getByLabelText supports accessibilityLabelledBy', async () => {
173173
<TextInput testID="textInput" accessibilityLabelledBy="label" />
174174
</>
175175
);
176-
expect(getByLabelText('Label for input')).toEqual(getByTestId('textInput'));
177-
expect(getByLabelText(/input/)).toEqual(getByTestId('textInput'));
176+
177+
expect(getByLabelText('Label for input')).toBe(getByTestId('textInput'));
178+
expect(getByLabelText(/input/)).toBe(getByTestId('textInput'));
178179
});
179180

180181
test('getByLabelText supports nested accessibilityLabelledBy', async () => {
@@ -187,6 +188,6 @@ test('getByLabelText supports nested accessibilityLabelledBy', async () => {
187188
</>
188189
);
189190

190-
expect(getByLabelText('Label for input')).toEqual(getByTestId('textInput'));
191-
expect(getByLabelText(/input/)).toEqual(getByTestId('textInput'));
191+
expect(getByLabelText('Label for input')).toBe(getByTestId('textInput'));
192+
expect(getByLabelText(/input/)).toBe(getByTestId('textInput'));
192193
});

src/queries/testId.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const getNodeByTestId = (
2020
options: TextMatchOptions = {}
2121
) => {
2222
const { exact, normalizer } = options;
23-
return matches(testID, node.props?.testID, normalizer, exact);
23+
return matches(testID, node.props.testID, normalizer, exact);
2424
};
2525

2626
const queryAllByTestId = (
@@ -30,13 +30,13 @@ const queryAllByTestId = (
3030
queryOptions?: ByTestIdOptions
3131
) => Array<ReactTestInstance>) =>
3232
function queryAllByTestIdFn(testId, queryOptions) {
33-
const results = findAll(
33+
return findAll(
3434
instance,
35-
(node) => getNodeByTestId(node, testId, queryOptions),
35+
(node) =>
36+
typeof node.type === 'string' &&
37+
getNodeByTestId(node, testId, queryOptions),
3638
queryOptions
3739
);
38-
39-
return results.filter((element) => typeof element.type === 'string');
4040
};
4141

4242
const getMultipleError = (testId: TextMatch) =>

0 commit comments

Comments
 (0)