Skip to content

Commit a62e681

Browse files
ShaswatPrabhatmdjastrzebski
authored andcommitted
Add tests for hintText and string check
1 parent e916842 commit a62e681

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/queries/__tests__/text.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,27 @@ describe('supports TextMatch options', () => {
342342
expect(getAllByTestId('test', { exact: false })).toHaveLength(2);
343343
});
344344

345+
test('getByHintText, getByHintText', () => {
346+
const { getByHintText, getAllByHintText } = render(
347+
<View>
348+
<View accessibilityHint="test" />
349+
<View accessibilityHint="tests id" />
350+
</View>
351+
);
352+
expect(getByHintText('id', { exact: false })).toBeTruthy();
353+
expect(getAllByHintText('test', { exact: false })).toHaveLength(2);
354+
});
355+
test('getByHintText, getByHintText and exact = true', () => {
356+
const { queryByHintText, getAllByHintText } = render(
357+
<View>
358+
<View accessibilityHint="test" />
359+
<View accessibilityHint="tests id" />
360+
</View>
361+
);
362+
expect(queryByHintText('id', { exact: true })).toBeNull();
363+
expect(getAllByHintText('test', { exact: true })).toHaveLength(1);
364+
});
365+
345366
test('with TextMatch option exact === false text search is NOT case sensitive', () => {
346367
const { getByText, getAllByText } = render(
347368
<View>

src/queries/hintText.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ const queryAllByHintText = (
2727
queryOptions?: TextMatchOptions
2828
) => Array<ReactTestInstance>) =>
2929
function queryAllByA11yHintFn(hint, queryOptions) {
30-
return instance
31-
.findAll((node) => getNodeByHintText(node, hint, queryOptions))
32-
.filter((element) => typeof element.type === 'string');
30+
return instance.findAll(
31+
(node) =>
32+
typeof node.type === 'string' &&
33+
getNodeByHintText(node, hint, queryOptions)
34+
);
3335
};
3436

3537
const getMultipleError = (hint: TextMatch) =>

0 commit comments

Comments
 (0)