|
1 | 1 | import React from 'react'; |
2 | | -import { Picker, Switch, View } from 'react-native'; |
| 2 | +import { Picker, Switch, View, Text, TextInput, Button } from 'react-native'; |
3 | 3 |
|
4 | 4 | import { render, queryByProp, queryByTestId, cleanup } from '../../'; |
5 | 5 |
|
@@ -33,3 +33,47 @@ it('should render test', () => { |
33 | 33 |
|
34 | 34 | expect(getByDisplayValue(true)).toBeTruthy(); |
35 | 35 | }); |
| 36 | + |
| 37 | +test('selector option in queries filter out elements', () => { |
| 38 | + function filterByLabel(label) { |
| 39 | + return { |
| 40 | + selector: ({ props }) => props.accessibilityLabel === label, |
| 41 | + }; |
| 42 | + } |
| 43 | + |
| 44 | + const { getByText, getByRole, getByDisplayValue, getByTitle } = render( |
| 45 | + <> |
| 46 | + <Text>hello world</Text> |
| 47 | + <Text accessibilityLabel="labelled">hello world</Text> |
| 48 | + |
| 49 | + <View accessibilityRole="link" /> |
| 50 | + <View accessibilityRole="link" accessibilityLabel="labelled" /> |
| 51 | + |
| 52 | + <TextInput value="hello joe" /> |
| 53 | + <TextInput value="hello joe" accessibilityLabel="labelled" /> |
| 54 | + |
| 55 | + <Button title="hello joe" /> |
| 56 | + <Button title="hello joe" accessibilityLabel="labelled" /> |
| 57 | + </>, |
| 58 | + ); |
| 59 | + |
| 60 | + // more than one match: |
| 61 | + expect(() => getByText(/hello world/i)).toThrow(); |
| 62 | + // filtered |
| 63 | + getByText(/hello world/i, filterByLabel('labelled')); |
| 64 | + |
| 65 | + // more than one match: |
| 66 | + expect(() => getByRole('link')).toThrow(); |
| 67 | + // filtered |
| 68 | + getByRole('link', filterByLabel('labelled')); |
| 69 | + |
| 70 | + // more than one match: |
| 71 | + expect(() => getByDisplayValue(/hello joe/i)).toThrow(); |
| 72 | + // filtered |
| 73 | + getByDisplayValue(/hello joe/i, filterByLabel('labelled')); |
| 74 | + |
| 75 | + // more than one match: |
| 76 | + expect(() => getByTitle(/hello joe/i)).toThrow(); |
| 77 | + // filtered |
| 78 | + getByTitle(/hello joe/i, filterByLabel('labelled')); |
| 79 | +}); |
0 commit comments