diff --git a/.circleci/config.yml b/.circleci/config.yml index 553eb356a..5867dcf81 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,7 +54,7 @@ jobs: steps: - attach_workspace: at: ~/react-native-testing-library - - run: yarn test + - run: yarn test:ci - store_artifacts: path: coverage destination: coverage diff --git a/examples/reactnavigation/jest-setup.js b/examples/reactnavigation/jest-setup.js index 161b6bc2e..baa4ed853 100644 --- a/examples/reactnavigation/jest-setup.js +++ b/examples/reactnavigation/jest-setup.js @@ -11,4 +11,4 @@ jest.mock('react-native-reanimated', () => { }); // Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing -jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper'); +jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); diff --git a/jestSetup.js b/jestSetup.js new file mode 100644 index 000000000..7060fd312 --- /dev/null +++ b/jestSetup.js @@ -0,0 +1 @@ +jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); diff --git a/package.json b/package.json index aff747ce7..b7cff3244 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "scripts": { "clean": "del build", "test": "jest", + "test:ci": "jest --maxWorkers=2", "typecheck": "tsc", "flow": "flow", "copy-flowtypes": "cp typings/index.flow.js build", @@ -83,6 +84,9 @@ }, "jest": { "preset": "./jest-preset", + "setupFiles": [ + "./jestSetup.js" + ], "testPathIgnorePatterns": [ "timerUtils", "examples/" diff --git a/src/helpers/matchers/__tests__/matchArrayValue.test.ts b/src/helpers/matchers/__tests__/matchArrayValue.test.ts new file mode 100644 index 000000000..c9141916b --- /dev/null +++ b/src/helpers/matchers/__tests__/matchArrayValue.test.ts @@ -0,0 +1,34 @@ +import { matchArrayProp } from '../matchArrayProp'; + +test('returns true given 2 identical prop and matcher', () => { + expect(matchArrayProp(['banana'], ['banana'])).toEqual(true); + expect(matchArrayProp(['banana', 'apple'], ['banana', 'apple'])).toEqual( + true + ); +}); + +test('returns true when the prop contains all the values of the matcher', () => { + expect( + matchArrayProp(['banana', 'apple', 'orange'], ['banana', 'orange']) + ).toEqual(true); +}); + +test('returns false when the prop does not contain all the values of the matcher', () => { + expect( + matchArrayProp(['banana', 'apple', 'orange'], ['banana', 'pear']) + ).toEqual(false); +}); + +test('returns false when prop is undefined', () => { + expect(matchArrayProp(undefined, ['banana'])).toEqual(false); +}); + +test('returns false when the matcher is an empty list', () => { + expect(matchArrayProp(['banana'], [])).toEqual(false); +}); + +test('returns false given 2 different prop and matchers', () => { + expect(matchArrayProp(['banana', 'apple'], ['banana', 'orange'])).toEqual( + false + ); +}); diff --git a/src/helpers/matchers/__tests__/matchObject.test.ts b/src/helpers/matchers/__tests__/matchObject.test.ts new file mode 100644 index 000000000..a87ed52b0 --- /dev/null +++ b/src/helpers/matchers/__tests__/matchObject.test.ts @@ -0,0 +1,37 @@ +import { matchObjectProp } from '../matchObjectProp'; + +test('returns true given 2 identical objects', () => { + expect(matchObjectProp({ fruit: 'banana' }, { fruit: 'banana' })).toEqual( + true + ); + expect( + matchObjectProp( + { fruit: 'banana', isRipe: true }, + { fruit: 'banana', isRipe: true } + ) + ).toEqual(true); +}); + +test('returns false when one of the param is an empty object', () => { + expect(matchObjectProp({}, { fruit: 'banana' })).toEqual(false); + expect(matchObjectProp({ fruit: 'banana' }, {})).toEqual(false); +}); + +test('returns false given an undefined prop', () => { + expect(matchObjectProp(undefined, { fruit: 'banana' })).toEqual(false); +}); + +test('returns false given 2 different non empty objects', () => { + expect(matchObjectProp({ fruit: 'banana' }, { fruits: 'banana' })).toEqual( + false + ); + expect(matchObjectProp({ fruit: 'banana' }, { fruit: 'orange' })).toEqual( + false + ); + expect( + matchObjectProp( + { fruit: 'banana', isRipe: true }, + { fruit: 'banana', ripe: true } + ) + ).toEqual(false); +}); diff --git a/src/helpers/matchers/__tests__/matchStringValue.test.ts b/src/helpers/matchers/__tests__/matchStringValue.test.ts new file mode 100644 index 000000000..a34b00d00 --- /dev/null +++ b/src/helpers/matchers/__tests__/matchStringValue.test.ts @@ -0,0 +1,15 @@ +import { matchStringProp } from '../matchStringProp'; + +test.each` + prop | matcher | expectedResult + ${'hey'} | ${'hey'} | ${true} + ${'hey'} | ${/hey/} | ${true} + ${'hey'} | ${'heyyyy'} | ${false} + ${'hey'} | ${/heyyy/} | ${false} + ${undefined} | ${'hey'} | ${false} +`( + 'returns $expectedResult given prop $prop and matcher $matcher', + ({ prop, matcher, expectedResult }) => { + expect(matchStringProp(prop, matcher)).toEqual(expectedResult); + } +); diff --git a/src/helpers/matchers/matchArrayProp.ts b/src/helpers/matchers/matchArrayProp.ts new file mode 100644 index 000000000..bdd2cbcf8 --- /dev/null +++ b/src/helpers/matchers/matchArrayProp.ts @@ -0,0 +1,21 @@ +/** + * Matches whether given array prop contains the given value, or all given values. + * + * @param prop - The array prop to match. + * @param matcher - The value or values to be included in the array. + * @returns Whether the array prop contains the given value, or all given values. + */ +export function matchArrayProp( + prop: Array | undefined, + matcher: string | Array +): boolean { + if (!prop || matcher.length === 0) { + return false; + } + + if (typeof matcher === 'string') { + return prop.includes(matcher); + } + + return matcher.every((e) => prop.includes(e)); +} diff --git a/src/helpers/matchers/matchObjectProp.ts b/src/helpers/matchers/matchObjectProp.ts new file mode 100644 index 000000000..6373c25ed --- /dev/null +++ b/src/helpers/matchers/matchObjectProp.ts @@ -0,0 +1,25 @@ +/** + * check that each key value pair of the objects match + * BE CAREFUL it works only for 1 level deep key value pairs + * won't work for nested objects + */ + +/** + * Matches whether given object prop contains all key/value pairs. + * @param prop - The object prop to match. + * @param matcher - The key/value pairs to be included in the object. + * @returns Whether the object prop contains all key/value pairs. + */ +export function matchObjectProp>( + prop: T | undefined, + matcher: T +): boolean { + if (!prop || Object.keys(matcher).length === 0) { + return false; + } + + return ( + Object.keys(prop).length !== 0 && + Object.keys(matcher).every((key) => prop[key] === matcher[key]) + ); +} diff --git a/src/helpers/matchers/matchStringProp.ts b/src/helpers/matchers/matchStringProp.ts new file mode 100644 index 000000000..4f63de1a6 --- /dev/null +++ b/src/helpers/matchers/matchStringProp.ts @@ -0,0 +1,23 @@ +import { TextMatch } from '../../matches'; + +/** + * Matches the given string property again string or regex matcher. + * + * @param prop - The string prop to match. + * @param matcher - The string or regex to match. + * @returns - Whether the string prop matches the given string or regex. + */ +export function matchStringProp( + prop: string | undefined, + matcher: TextMatch +): boolean { + if (!prop) { + return false; + } + + if (typeof matcher === 'string') { + return prop === matcher; + } + + return prop.match(matcher) != null; +} diff --git a/src/queries/__tests__/a11yAPI.test.tsx b/src/queries/__tests__/a11yAPI.test.tsx deleted file mode 100644 index b195b13ad..000000000 --- a/src/queries/__tests__/a11yAPI.test.tsx +++ /dev/null @@ -1,418 +0,0 @@ -import * as React from 'react'; -import { TouchableOpacity, Text } from 'react-native'; -import { render } from '../..'; - -const BUTTON_LABEL = 'cool button'; -const BUTTON_HINT = 'click this button'; -const TEXT_LABEL = 'cool text'; -const TEXT_HINT = 'static text'; -// Little hack to make all the methods happy with type -const NO_MATCHES_TEXT: any = 'not-existent-element'; -const FOUND_TWO_INSTANCES = 'Expected 1 but found 2 instances'; - -const getNoInstancesFoundMessage = ( - name: string, - value: string = NO_MATCHES_TEXT, - includeQuotes: boolean = true -) => { - const quote = includeQuotes ? '"' : ''; - return `No instances found with ${name} ${quote}${value}${quote}`; -}; - -const Typography = ({ children, ...rest }: any) => { - return {children}; -}; - -const waitForOptions = { timeout: 10 }; - -class Button extends React.Component { - render() { - return ( - - - {this.props.children} - - - ); - } -} - -function Section() { - return ( - <> - - Title - - - - ); -} - -test('getByLabelText, queryByLabelText, findByLabelText', async () => { - const { getByLabelText, queryByLabelText, findByLabelText } = render( -
- ); - - expect(getByLabelText(BUTTON_LABEL).props.accessibilityLabel).toEqual( - BUTTON_LABEL - ); - const button = queryByLabelText(/button/g); - expect(button?.props.accessibilityLabel).toEqual(BUTTON_LABEL); - - expect(() => getByLabelText(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityLabel') - ); - expect(queryByLabelText(NO_MATCHES_TEXT)).toBeNull(); - - expect(() => getByLabelText(TEXT_LABEL)).toThrow(FOUND_TWO_INSTANCES); - expect(() => queryByLabelText(TEXT_LABEL)).toThrow(FOUND_TWO_INSTANCES); - - const asyncButton = await findByLabelText(BUTTON_LABEL); - expect(asyncButton.props.accessibilityLabel).toEqual(BUTTON_LABEL); - await expect( - findByLabelText(NO_MATCHES_TEXT, waitForOptions) - ).rejects.toThrow(getNoInstancesFoundMessage('accessibilityLabel')); - - await expect(findByLabelText(TEXT_LABEL, waitForOptions)).rejects.toThrow( - FOUND_TWO_INSTANCES - ); -}); - -test('getAllByLabelText, queryAllByLabelText, findAllByLabelText', async () => { - const { getAllByLabelText, queryAllByLabelText, findAllByLabelText } = render( -
- ); - - expect(getAllByLabelText(TEXT_LABEL)).toHaveLength(2); - expect(queryAllByLabelText(/cool/g)).toHaveLength(3); - - expect(() => getAllByLabelText(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityLabel') - ); - expect(queryAllByLabelText(NO_MATCHES_TEXT)).toEqual([]); - - await expect(findAllByLabelText(TEXT_LABEL)).resolves.toHaveLength(2); - await expect(findAllByLabelText(NO_MATCHES_TEXT)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityLabel') - ); -}); - -test('getByA11yHint, queryByA11yHint, findByA11yHint', async () => { - const { getByA11yHint, queryByA11yHint, findByA11yHint } = render( -
- ); - - expect(getByA11yHint(BUTTON_HINT).props.accessibilityHint).toEqual( - BUTTON_HINT - ); - const button = queryByA11yHint(/button/g); - expect(button?.props.accessibilityHint).toEqual(BUTTON_HINT); - - expect(() => getByA11yHint(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityHint') - ); - expect(queryByA11yHint(NO_MATCHES_TEXT)).toBeNull(); - - expect(() => getByA11yHint(TEXT_HINT)).toThrow(FOUND_TWO_INSTANCES); - expect(() => queryByA11yHint(TEXT_HINT)).toThrow(FOUND_TWO_INSTANCES); - - const asyncButton = await findByA11yHint(BUTTON_HINT); - expect(asyncButton.props.accessibilityHint).toEqual(BUTTON_HINT); - await expect(findByA11yHint(NO_MATCHES_TEXT, waitForOptions)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityHint') - ); - await expect(findByA11yHint(TEXT_HINT, waitForOptions)).rejects.toThrow( - FOUND_TWO_INSTANCES - ); -}); - -test('getAllByA11yHint, queryAllByA11yHint, findAllByA11yHint', async () => { - const { getAllByA11yHint, queryAllByA11yHint, findAllByA11yHint } = render( -
- ); - - expect(getAllByA11yHint(TEXT_HINT)).toHaveLength(2); - expect(queryAllByA11yHint(/static/g)).toHaveLength(2); - - expect(() => getAllByA11yHint(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityHint') - ); - expect(queryAllByA11yHint(NO_MATCHES_TEXT)).toEqual([]); - - await expect(findAllByA11yHint(TEXT_HINT)).resolves.toHaveLength(2); - await expect(findAllByA11yHint(NO_MATCHES_TEXT)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityHint') - ); -}); - -test('getByRole, queryByRole, findByRole', async () => { - const { getByRole, queryByRole, findByRole } = render(
); - - expect(getByRole('button').props.accessibilityRole).toEqual('button'); - const button = queryByRole(/button/g); - expect(button?.props.accessibilityRole).toEqual('button'); - - expect(() => getByRole(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityRole') - ); - expect(queryByRole(NO_MATCHES_TEXT)).toBeNull(); - - expect(() => getByRole('link')).toThrow(FOUND_TWO_INSTANCES); - expect(() => queryByRole('link')).toThrow(FOUND_TWO_INSTANCES); - - const asyncButton = await findByRole('button'); - expect(asyncButton.props.accessibilityRole).toEqual('button'); - await expect(findByRole(NO_MATCHES_TEXT, waitForOptions)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityRole') - ); - await expect(findByRole('link')).rejects.toThrow(FOUND_TWO_INSTANCES); -}); - -test('getAllByRole, queryAllByRole, findAllByRole', async () => { - const { getAllByRole, queryAllByRole, findAllByRole } = render(
); - - expect(getAllByRole('link')).toHaveLength(2); - expect(queryAllByRole(/ink/g)).toHaveLength(2); - - expect(() => getAllByRole(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityRole') - ); - expect(queryAllByRole(NO_MATCHES_TEXT)).toEqual([]); - - await expect(findAllByRole('link')).resolves.toHaveLength(2); - await expect(findAllByRole(NO_MATCHES_TEXT, waitForOptions)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityRole') - ); -}); - -// TODO: accessibilityStates was removed from RN 0.62 -test.skip('getByA11yStates, queryByA11yStates', () => { - const { getByA11yStates, queryByA11yStates } = render(
); - - expect(getByA11yStates('disabled').props.accessibilityStates).toEqual([ - 'selected', - 'disabled', - ]); - const disabled = queryByA11yStates(['disabled']); - expect(disabled?.props.accessibilityStates).toMatchObject([ - 'selected', - 'disabled', - ]); - const disabledSelected = queryByA11yStates(['selected', 'disabled']); - expect(disabledSelected?.props.accessibilityStates).toEqual([ - 'selected', - 'disabled', - ]); - - expect(() => getByA11yStates(NO_MATCHES_TEXT)).toThrow( - getNoInstancesFoundMessage('accessibilityStates') - ); - expect(queryByA11yStates(NO_MATCHES_TEXT)).toBeNull(); - expect(queryByA11yStates([])).toBeNull(); - - expect(() => getByA11yStates('selected')).toThrow(FOUND_TWO_INSTANCES); - expect(() => queryByA11yStates('selected')).toThrow(FOUND_TWO_INSTANCES); -}); - -// TODO: accessibilityStates was removed from RN 0.62 -test.skip('getAllByA11yStates, queryAllByA11yStates', () => { - const { getAllByA11yStates, queryAllByA11yStates } = render(
); - - expect(getAllByA11yStates('selected')).toHaveLength(3); - expect(queryAllByA11yStates(['selected'])).toHaveLength(3); - - expect(() => getAllByA11yStates([])).toThrow( - getNoInstancesFoundMessage('accessibilityStates') - ); - expect(queryAllByA11yStates(NO_MATCHES_TEXT)).toEqual([]); -}); - -test('getByA11yState, queryByA11yState, findByA11yState', async () => { - const { getByA11yState, queryByA11yState, findByA11yState } = render( -
- ); - - expect(getByA11yState({ selected: true }).props.accessibilityState).toEqual({ - selected: true, - expanded: false, - }); - expect( - queryByA11yState({ selected: true })?.props.accessibilityState - ).toEqual({ - selected: true, - expanded: false, - }); - - expect(() => getByA11yState({ disabled: true })).toThrow( - getNoInstancesFoundMessage( - 'accessibilityState', - '{"disabled": true}', - false - ) - ); - expect(queryByA11yState({ disabled: true })).toEqual(null); - - expect(() => getByA11yState({ expanded: false })).toThrow( - FOUND_TWO_INSTANCES - ); - expect(() => queryByA11yState({ expanded: false })).toThrow( - FOUND_TWO_INSTANCES - ); - - const asyncButton = await findByA11yState({ selected: true }); - expect(asyncButton.props.accessibilityState).toEqual({ - selected: true, - expanded: false, - }); - await expect( - findByA11yState({ disabled: true }, waitForOptions) - ).rejects.toThrow( - getNoInstancesFoundMessage( - 'accessibilityState', - '{"disabled": true}', - false - ) - ); - await expect( - findByA11yState({ expanded: false }, waitForOptions) - ).rejects.toThrow(FOUND_TWO_INSTANCES); -}); - -test('getAllByA11yState, queryAllByA11yState, findAllByA11yState', async () => { - const { getAllByA11yState, queryAllByA11yState, findAllByA11yState } = render( -
- ); - - expect(getAllByA11yState({ selected: true })).toHaveLength(1); - expect(queryAllByA11yState({ selected: true })).toHaveLength(1); - - expect(() => getAllByA11yState({ disabled: true })).toThrow( - getNoInstancesFoundMessage( - 'accessibilityState', - '{"disabled": true}', - false - ) - ); - expect(queryAllByA11yState({ disabled: true })).toEqual([]); - - expect(getAllByA11yState({ expanded: false })).toHaveLength(2); - expect(queryAllByA11yState({ expanded: false })).toHaveLength(2); - - await expect(findAllByA11yState({ selected: true })).resolves.toHaveLength(1); - await expect( - findAllByA11yState({ disabled: true }, waitForOptions) - ).rejects.toThrow( - getNoInstancesFoundMessage( - 'accessibilityState', - '{"disabled": true}', - false - ) - ); - await expect(findAllByA11yState({ expanded: false })).resolves.toHaveLength( - 2 - ); -}); - -test('getByA11yValue, queryByA11yValue, findByA11yValue', async () => { - const { getByA11yValue, queryByA11yValue, findByA11yValue } = render( -
- ); - - expect(getByA11yValue({ min: 40 }).props.accessibilityValue).toEqual({ - min: 40, - max: 60, - }); - expect(queryByA11yValue({ min: 40 })?.props.accessibilityValue).toEqual({ - min: 40, - max: 60, - }); - - expect(() => getByA11yValue({ min: 50 })).toThrow( - getNoInstancesFoundMessage('accessibilityValue', '{"min": 50}', false) - ); - expect(queryByA11yValue({ min: 50 })).toEqual(null); - - expect(() => getByA11yValue({ max: 60 })).toThrow(FOUND_TWO_INSTANCES); - expect(() => queryByA11yValue({ max: 60 })).toThrow(FOUND_TWO_INSTANCES); - - const asyncElement = await findByA11yValue({ min: 40 }); - expect(asyncElement.props.accessibilityValue).toEqual({ - min: 40, - max: 60, - }); - await expect(findByA11yValue({ min: 50 }, waitForOptions)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityValue', '{"min": 50}', false) - ); - await expect(findByA11yValue({ max: 60 }, waitForOptions)).rejects.toThrow( - FOUND_TWO_INSTANCES - ); -}); - -test('getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue', async () => { - const { getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue } = render( -
- ); - - expect(getAllByA11yValue({ min: 40 })).toHaveLength(1); - expect(queryAllByA11yValue({ min: 40 })).toHaveLength(1); - - expect(() => getAllByA11yValue({ min: 50 })).toThrow( - getNoInstancesFoundMessage('accessibilityValue', '{"min": 50}', false) - ); - expect(queryAllByA11yValue({ min: 50 })).toEqual([]); - - expect(queryAllByA11yValue({ max: 60 })).toHaveLength(2); - expect(getAllByA11yValue({ max: 60 })).toHaveLength(2); - - await expect(findAllByA11yValue({ min: 40 })).resolves.toHaveLength(1); - await expect(findAllByA11yValue({ min: 50 }, waitForOptions)).rejects.toThrow( - getNoInstancesFoundMessage('accessibilityValue', '{"min": 50}', false) - ); - await expect(findAllByA11yValue({ max: 60 })).resolves.toHaveLength(2); -}); - -test('a11y hint queries have aliases', () => { - const { - getByA11yHint, - getByHintText, - queryByA11yHint, - queryByHintText, - findByA11yHint, - findByHintText, - getAllByA11yHint, - getAllByHintText, - queryAllByA11yHint, - queryAllByHintText, - findAllByA11yHint, - findAllByHintText, - } = render(
); - - // Assert that query aliases are referencing the same function - expect(getByA11yHint).toBe(getByHintText); - expect(queryByA11yHint).toBe(queryByHintText); - expect(findByA11yHint).toBe(findByHintText); - expect(getAllByA11yHint).toBe(getAllByHintText); - expect(queryAllByA11yHint).toBe(queryAllByHintText); - expect(findAllByA11yHint).toBe(findAllByHintText); -}); diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx new file mode 100644 index 000000000..c15c078b4 --- /dev/null +++ b/src/queries/__tests__/a11yState.test.tsx @@ -0,0 +1,98 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const TEXT_LABEL = 'cool text'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityState: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityState: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + + {children} + + +); + +const Section = () => ( + <> + Title + + +); + +test('getByA11yState, queryByA11yState, findByA11yState', async () => { + const { getByA11yState, queryByA11yState, findByA11yState } = render( +
+ ); + + expect(getByA11yState({ selected: true }).props.accessibilityState).toEqual({ + selected: true, + expanded: false, + }); + expect( + queryByA11yState({ selected: true })?.props.accessibilityState + ).toEqual({ + selected: true, + expanded: false, + }); + + expect(() => getByA11yState({ disabled: true })).toThrow( + getNoInstancesFoundMessage('{"disabled":true}') + ); + expect(queryByA11yState({ disabled: true })).toEqual(null); + + expect(() => getByA11yState({ expanded: false })).toThrow( + getMultipleInstancesFoundMessage('{"expanded":false}') + ); + expect(() => queryByA11yState({ expanded: false })).toThrow( + getMultipleInstancesFoundMessage('{"expanded":false}') + ); + + const asyncButton = await findByA11yState({ selected: true }); + expect(asyncButton.props.accessibilityState).toEqual({ + selected: true, + expanded: false, + }); + await expect(findByA11yState({ disabled: true })).rejects.toThrow( + getNoInstancesFoundMessage('{"disabled":true}') + ); + await expect(findByA11yState({ expanded: false })).rejects.toThrow( + getMultipleInstancesFoundMessage('{"expanded":false}') + ); +}); + +test('getAllByA11yState, queryAllByA11yState, findAllByA11yState', async () => { + const { getAllByA11yState, queryAllByA11yState, findAllByA11yState } = render( +
+ ); + + expect(getAllByA11yState({ selected: true })).toHaveLength(1); + expect(queryAllByA11yState({ selected: true })).toHaveLength(1); + + expect(() => getAllByA11yState({ disabled: true })).toThrow( + getNoInstancesFoundMessage('{"disabled":true}') + ); + expect(queryAllByA11yState({ disabled: true })).toEqual([]); + + expect(getAllByA11yState({ expanded: false })).toHaveLength(2); + expect(queryAllByA11yState({ expanded: false })).toHaveLength(2); + + await expect(findAllByA11yState({ selected: true })).resolves.toHaveLength(1); + await expect(findAllByA11yState({ disabled: true })).rejects.toThrow( + getNoInstancesFoundMessage('{"disabled":true}') + ); + await expect(findAllByA11yState({ expanded: false })).resolves.toHaveLength( + 2 + ); +}); diff --git a/src/queries/__tests__/a11yStates.test.tsx b/src/queries/__tests__/a11yStates.test.tsx new file mode 100644 index 000000000..7a01b0725 --- /dev/null +++ b/src/queries/__tests__/a11yStates.test.tsx @@ -0,0 +1,86 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const TEXT_LABEL = 'cool text'; +// Little hack to make all the methods happy with type +const NO_MATCHES_TEXT: any = 'not-existent-element'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityStates: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityStates: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + {children} + +); + +const Section = () => ( + <> + + Title + + + +); + +// TODO: accessibilityStates was removed from RN 0.62 +test.skip('getByA11yStates, queryByA11yStates', () => { + const { getByA11yStates, queryByA11yStates } = render(
); + + expect(getByA11yStates('disabled').props.accessibilityStates).toEqual([ + 'selected', + 'disabled', + ]); + const disabled = queryByA11yStates(['disabled']); + expect(disabled?.props.accessibilityStates).toMatchObject([ + 'selected', + 'disabled', + ]); + const disabledSelected = queryByA11yStates(['selected', 'disabled']); + expect(disabledSelected?.props.accessibilityStates).toEqual([ + 'selected', + 'disabled', + ]); + + expect(() => getByA11yStates(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage('accessibilityStates') + ); + expect(queryByA11yStates(NO_MATCHES_TEXT)).toBeNull(); + expect(queryByA11yStates([])).toBeNull(); + + expect(() => getByA11yStates('selected')).toThrow( + getMultipleInstancesFoundMessage('["selected"]') + ); + expect(() => queryByA11yStates('selected')).toThrow( + getMultipleInstancesFoundMessage('["selected"]') + ); +}); + +// TODO: accessibilityStates was removed from RN 0.62 +test.skip('getAllByA11yStates, queryAllByA11yStates', () => { + const { getAllByA11yStates, queryAllByA11yStates } = render(
); + + expect(getAllByA11yStates('selected')).toHaveLength(3); + expect(queryAllByA11yStates(['selected'])).toHaveLength(3); + + expect(() => getAllByA11yStates([])).toThrow( + getNoInstancesFoundMessage('[]') + ); + expect(queryAllByA11yStates(NO_MATCHES_TEXT)).toEqual([]); +}); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx new file mode 100644 index 000000000..ddb4201a4 --- /dev/null +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -0,0 +1,94 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const TEXT_LABEL = 'cool text'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityValue: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityValue: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + + {children} + + +); + +const Section = () => ( + <> + Title + + +); + +test('getByA11yValue, queryByA11yValue, findByA11yValue', async () => { + const { getByA11yValue, queryByA11yValue, findByA11yValue } = render( +
+ ); + + expect(getByA11yValue({ min: 40 }).props.accessibilityValue).toEqual({ + min: 40, + max: 60, + }); + expect(queryByA11yValue({ min: 40 })?.props.accessibilityValue).toEqual({ + min: 40, + max: 60, + }); + + expect(() => getByA11yValue({ min: 50 })).toThrow( + getNoInstancesFoundMessage('{"min":50}') + ); + expect(queryByA11yValue({ min: 50 })).toEqual(null); + + expect(() => getByA11yValue({ max: 60 })).toThrow( + getMultipleInstancesFoundMessage('{"max":60}') + ); + expect(() => queryByA11yValue({ max: 60 })).toThrow( + getMultipleInstancesFoundMessage('{"max":60}') + ); + + const asyncElement = await findByA11yValue({ min: 40 }); + expect(asyncElement.props.accessibilityValue).toEqual({ + min: 40, + max: 60, + }); + await expect(findByA11yValue({ min: 50 })).rejects.toThrow( + getNoInstancesFoundMessage('{"min":50}') + ); + await expect(findByA11yValue({ max: 60 })).rejects.toThrow( + getMultipleInstancesFoundMessage('{"max":60}') + ); +}); + +test('getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue', async () => { + const { getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue } = render( +
+ ); + + expect(getAllByA11yValue({ min: 40 })).toHaveLength(1); + expect(queryAllByA11yValue({ min: 40 })).toHaveLength(1); + + expect(() => getAllByA11yValue({ min: 50 })).toThrow( + getNoInstancesFoundMessage('{"min":50}') + ); + expect(queryAllByA11yValue({ min: 50 })).toEqual([]); + + expect(queryAllByA11yValue({ max: 60 })).toHaveLength(2); + expect(getAllByA11yValue({ max: 60 })).toHaveLength(2); + + await expect(findAllByA11yValue({ min: 40 })).resolves.toHaveLength(1); + await expect(findAllByA11yValue({ min: 50 })).rejects.toThrow( + getNoInstancesFoundMessage('{"min":50}') + ); + await expect(findAllByA11yValue({ max: 60 })).resolves.toHaveLength(2); +}); diff --git a/src/queries/__tests__/hintText.test.tsx b/src/queries/__tests__/hintText.test.tsx new file mode 100644 index 000000000..6e5ddb5e7 --- /dev/null +++ b/src/queries/__tests__/hintText.test.tsx @@ -0,0 +1,86 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const BUTTON_HINT = 'click this button'; +const TEXT_HINT = 'static text'; +// Little hack to make all the methods happy with type +const NO_MATCHES_TEXT: any = 'not-existent-element'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityHint: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityHint: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + {children} + +); + +const Section = () => ( + <> + Title + + +); + +test('getByA11yHint, queryByA11yHint, findByA11yHint', async () => { + const { getByA11yHint, queryByA11yHint, findByA11yHint } = render( +
+ ); + + expect(getByA11yHint(BUTTON_HINT).props.accessibilityHint).toEqual( + BUTTON_HINT + ); + const button = queryByA11yHint(BUTTON_HINT); + expect(button?.props.accessibilityHint).toEqual(BUTTON_HINT); + + expect(() => getByA11yHint(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryByA11yHint(NO_MATCHES_TEXT)).toBeNull(); + + expect(() => getByA11yHint(TEXT_HINT)).toThrow( + getMultipleInstancesFoundMessage(TEXT_HINT) + ); + expect(() => queryByA11yHint(TEXT_HINT)).toThrow( + getMultipleInstancesFoundMessage(TEXT_HINT) + ); + + const asyncButton = await findByA11yHint(BUTTON_HINT); + expect(asyncButton.props.accessibilityHint).toEqual(BUTTON_HINT); + await expect(findByA11yHint(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + + await expect(findByA11yHint(TEXT_HINT)).rejects.toThrow( + getMultipleInstancesFoundMessage(TEXT_HINT) + ); +}); + +test('getAllByA11yHint, queryAllByA11yHint, findAllByA11yHint', async () => { + const { getAllByA11yHint, queryAllByA11yHint, findAllByA11yHint } = render( +
+ ); + + expect(getAllByA11yHint(TEXT_HINT)).toHaveLength(2); + expect(queryAllByA11yHint(TEXT_HINT)).toHaveLength(2); + + expect(() => getAllByA11yHint(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryAllByA11yHint(NO_MATCHES_TEXT)).toEqual([]); + + await expect(findAllByA11yHint(TEXT_HINT)).resolves.toHaveLength(2); + await expect(findAllByA11yHint(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); +}); diff --git a/src/queries/__tests__/labelText.test.tsx b/src/queries/__tests__/labelText.test.tsx new file mode 100644 index 000000000..8b9dc54e1 --- /dev/null +++ b/src/queries/__tests__/labelText.test.tsx @@ -0,0 +1,95 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const BUTTON_LABEL = 'cool button'; +const BUTTON_HINT = 'click this button'; +const TEXT_LABEL = 'cool text'; +const TEXT_HINT = 'static text'; +// Little hack to make all the methods happy with type +const NO_MATCHES_TEXT: any = 'not-existent-element'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityLabel: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityLabel: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + + {children} + + +); + +const Section = () => ( + <> + + Title + + + +); + +test('getByLabelText, queryByLabelText, findByLabelText', async () => { + const { getByLabelText, queryByLabelText, findByLabelText } = render( +
+ ); + + expect(getByLabelText(BUTTON_LABEL).props.accessibilityLabel).toEqual( + BUTTON_LABEL + ); + const button = queryByLabelText(/button/g); + expect(button?.props.accessibilityLabel).toEqual(BUTTON_LABEL); + + expect(() => getByLabelText(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryByLabelText(NO_MATCHES_TEXT)).toBeNull(); + + expect(() => getByLabelText(TEXT_LABEL)).toThrow( + getMultipleInstancesFoundMessage(TEXT_LABEL) + ); + expect(() => queryByLabelText(TEXT_LABEL)).toThrow( + getMultipleInstancesFoundMessage(TEXT_LABEL) + ); + + const asyncButton = await findByLabelText(BUTTON_LABEL); + expect(asyncButton.props.accessibilityLabel).toEqual(BUTTON_LABEL); + await expect(findByLabelText(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + + await expect(findByLabelText(TEXT_LABEL)).rejects.toThrow( + getMultipleInstancesFoundMessage(TEXT_LABEL) + ); +}); + +test('getAllByLabelText, queryAllByLabelText, findAllByLabelText', async () => { + const { getAllByLabelText, queryAllByLabelText, findAllByLabelText } = render( +
+ ); + + expect(getAllByLabelText(TEXT_LABEL)).toHaveLength(2); + expect(queryAllByLabelText(/cool/g)).toHaveLength(3); + + expect(() => getAllByLabelText(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryAllByLabelText(NO_MATCHES_TEXT)).toEqual([]); + + await expect(findAllByLabelText(TEXT_LABEL)).resolves.toHaveLength(2); + await expect(findAllByLabelText(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); +}); diff --git a/src/queries/__tests__/role.test.tsx b/src/queries/__tests__/role.test.tsx new file mode 100644 index 000000000..de5ebfd7f --- /dev/null +++ b/src/queries/__tests__/role.test.tsx @@ -0,0 +1,79 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import { render } from '../..'; + +const TEXT_LABEL = 'cool text'; + +// Little hack to make all the methods happy with type +const NO_MATCHES_TEXT: any = 'not-existent-element'; + +const getMultipleInstancesFoundMessage = (value: string) => { + return `Found multiple elements with accessibilityRole: ${value}`; +}; + +const getNoInstancesFoundMessage = (value: string) => { + return `Unable to find an element with accessibilityRole: ${value}`; +}; + +const Typography = ({ children, ...rest }: any) => { + return {children}; +}; + +const Button = ({ children }: { children: React.ReactNode }) => ( + + {children} + +); + +const Section = () => ( + <> + Title + + +); + +test('getByRole, queryByRole, findByRole', async () => { + const { getByRole, queryByRole, findByRole } = render(
); + + expect(getByRole('button').props.accessibilityRole).toEqual('button'); + const button = queryByRole(/button/g); + expect(button?.props.accessibilityRole).toEqual('button'); + + expect(() => getByRole(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryByRole(NO_MATCHES_TEXT)).toBeNull(); + + expect(() => getByRole('link')).toThrow( + getMultipleInstancesFoundMessage('link') + ); + expect(() => queryByRole('link')).toThrow( + getMultipleInstancesFoundMessage('link') + ); + + const asyncButton = await findByRole('button'); + expect(asyncButton.props.accessibilityRole).toEqual('button'); + await expect(findByRole(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + await expect(findByRole('link')).rejects.toThrow( + getMultipleInstancesFoundMessage('link') + ); +}); + +test('getAllByRole, queryAllByRole, findAllByRole', async () => { + const { getAllByRole, queryAllByRole, findAllByRole } = render(
); + + expect(getAllByRole('link')).toHaveLength(2); + expect(queryAllByRole(/ink/g)).toHaveLength(2); + + expect(() => getAllByRole(NO_MATCHES_TEXT)).toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); + expect(queryAllByRole(NO_MATCHES_TEXT)).toEqual([]); + + await expect(findAllByRole('link')).resolves.toHaveLength(2); + await expect(findAllByRole(NO_MATCHES_TEXT)).rejects.toThrow( + getNoInstancesFoundMessage(NO_MATCHES_TEXT) + ); +}); diff --git a/src/queries/a11yAPI.ts b/src/queries/a11yAPI.ts deleted file mode 100644 index 4b9f42e53..000000000 --- a/src/queries/a11yAPI.ts +++ /dev/null @@ -1,261 +0,0 @@ -import type { ReactTestInstance } from 'react-test-renderer'; -import type { AccessibilityRole, AccessibilityState } from 'react-native'; -import type { WaitForOptions } from '../waitFor'; -import type { TextMatch } from '../matches'; -import makeA11yQuery from './makeA11yQuery'; - -type AccessibilityStateKey = keyof AccessibilityState; -type A11yValue = { - min?: number; - max?: number; - now?: number; - text?: string; -}; - -type GetReturn = ReactTestInstance; -type GetAllReturn = Array; -type QueryReturn = ReactTestInstance | null; -type QueryAllReturn = Array; -type FindReturn = Promise; -type FindAllReturn = Promise; - -export type A11yAPI = { - // Label - getByLabelText: (label: TextMatch) => GetReturn; - getAllByLabelText: (label: TextMatch) => GetAllReturn; - queryByLabelText: (label: TextMatch) => QueryReturn; - queryAllByLabelText: (label: TextMatch) => QueryAllReturn; - findByLabelText: ( - label: TextMatch, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByLabelText: ( - label: TextMatch, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - - // Hint - getByA11yHint: (a11yHint: TextMatch) => GetReturn; - getByHintText: (a11yHint: TextMatch) => GetReturn; - getAllByA11yHint: (a11yHint: TextMatch) => GetAllReturn; - getAllByHintText: (a11yHint: TextMatch) => GetAllReturn; - queryByA11yHint: (a11yHint: TextMatch) => QueryReturn; - queryByHintText: (a11yHint: TextMatch) => QueryReturn; - queryAllByA11yHint: (a11yHint: TextMatch) => QueryAllReturn; - queryAllByHintText: (a11yHint: TextMatch) => QueryAllReturn; - findByA11yHint: ( - a11yHint: TextMatch, - waitForOptions?: WaitForOptions - ) => FindReturn; - findByHintText: ( - a11yHint: TextMatch, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByA11yHint: ( - a11yHint: TextMatch, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - findAllByHintText: ( - a11yHint: TextMatch, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - - // Role - getByRole: (role: AccessibilityRole | RegExp) => GetReturn; - getAllByRole: (role: AccessibilityRole | RegExp) => GetAllReturn; - queryByRole: (role: AccessibilityRole | RegExp) => QueryReturn; - queryAllByRole: (role: AccessibilityRole | RegExp) => QueryAllReturn; - findByRole: ( - role: AccessibilityRole, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByRole: ( - role: AccessibilityRole, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - - // States - getByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey | Array - ) => GetReturn; - getAllByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey | Array - ) => GetAllReturn; - queryByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey | Array - ) => QueryReturn; - queryAllByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey | Array - ) => QueryAllReturn; - findByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByA11yStates: ( - accessibilityStateKey: AccessibilityStateKey, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - - // State - getByA11yState: (accessibilityState: AccessibilityState) => GetReturn; - getAllByA11yState: (accessibilityState: AccessibilityState) => GetAllReturn; - queryByA11yState: (accessibilityState: AccessibilityState) => QueryReturn; - queryAllByA11yState: ( - accessibilityState: AccessibilityState - ) => QueryAllReturn; - findByA11yState: ( - accessibilityState: AccessibilityState, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByA11yState: ( - accessibilityState: AccessibilityState, - waitForOptions?: WaitForOptions - ) => FindAllReturn; - - // Value - getByA11yValue: (a11yValue: A11yValue) => GetReturn; - getAllByA11yValue: (a11yValue: A11yValue) => GetAllReturn; - queryByA11yValue: (a11yValue: A11yValue) => QueryReturn; - queryAllByA11yValue: (a11yValue: A11yValue) => QueryAllReturn; - findByA11yValue: ( - a11yValue: A11yValue, - waitForOptions?: WaitForOptions - ) => FindReturn; - findAllByA11yValue: ( - a11yValue: A11yValue, - waitForOptions?: WaitForOptions - ) => FindAllReturn; -}; - -export function matchStringValue( - prop: string | undefined, - matcher: TextMatch -): boolean { - if (!prop) { - return false; - } - - if (typeof matcher === 'string') { - return prop === matcher; - } - - return Boolean(prop.match(matcher)); -} - -export function matchArrayValue( - prop: Array | undefined, - matcher: string | Array -): boolean { - if (!prop || matcher.length === 0) { - return false; - } - - if (typeof matcher === 'string') { - return prop.includes(matcher); - } - - return !matcher.some((e) => !prop.includes(e)); -} - -export function matchObject>( - prop: T | undefined, - matcher: T -): boolean { - return prop - ? Object.keys(matcher).length !== 0 && - Object.keys(prop).length !== 0 && - !Object.keys(matcher).some((key) => prop[key] !== matcher[key]) - : false; -} - -export const a11yAPI = (instance: ReactTestInstance): A11yAPI => - ({ - ...makeA11yQuery( - 'accessibilityLabel', - { - getBy: ['getByLabelText'], - getAllBy: ['getAllByLabelText'], - queryBy: ['queryByLabelText'], - queryAllBy: ['queryAllByLabelText'], - findBy: ['findByLabelText'], - findAllBy: ['findAllByLabelText'], - }, - matchStringValue - )(instance), - ...makeA11yQuery( - 'accessibilityHint', - { - getBy: ['getByA11yHint', 'getByAccessibilityHint', 'getByHintText'], - getAllBy: [ - 'getAllByA11yHint', - 'getAllByAccessibilityHint', - 'getAllByHintText', - ], - queryBy: [ - 'queryByA11yHint', - 'queryByAccessibilityHint', - 'queryByHintText', - ], - queryAllBy: [ - 'queryAllByA11yHint', - 'queryAllByAccessibilityHint', - 'queryAllByHintText', - ], - findBy: ['findByA11yHint', 'findByAccessibilityHint', 'findByHintText'], - findAllBy: [ - 'findAllByA11yHint', - 'findAllByAccessibilityHint', - 'findAllByHintText', - ], - }, - matchStringValue - )(instance), - ...makeA11yQuery( - 'accessibilityRole', - { - getBy: ['getByRole'], - getAllBy: ['getAllByRole'], - queryBy: ['queryByRole'], - queryAllBy: ['queryAllByRole'], - findBy: ['findByRole'], - findAllBy: ['findAllByRole'], - }, - matchStringValue - )(instance), - ...makeA11yQuery( - 'accessibilityStates', - { - getBy: ['getByA11yStates', 'getByAccessibilityStates'], - getAllBy: ['getAllByA11yStates', 'getAllByAccessibilityStates'], - queryBy: ['queryByA11yStates', 'queryByAccessibilityStates'], - queryAllBy: ['queryAllByA11yStates', 'queryAllByAccessibilityStates'], - findBy: ['findByA11yStates', 'findByAccessibilityStates'], - findAllBy: ['findAllByA11yStates', 'findAllByAccessibilityStates'], - }, - matchArrayValue - )(instance), - ...makeA11yQuery( - 'accessibilityState', - { - getBy: ['getByA11yState', 'getByAccessibilityState'], - getAllBy: ['getAllByA11yState', 'getAllByAccessibilityState'], - queryBy: ['queryByA11yState', 'queryByAccessibilityState'], - queryAllBy: ['queryAllByA11yState', 'queryAllByAccessibilityState'], - findBy: ['findByA11yState', 'findByAccessibilityState'], - findAllBy: ['findAllByA11yState', 'findAllByAccessibilityState'], - }, - matchObject - )(instance), - ...makeA11yQuery( - 'accessibilityValue', - { - getBy: ['getByA11yValue', 'getByAccessibilityValue'], - getAllBy: ['getAllByA11yValue', 'getAllByAccessibilityValue'], - queryBy: ['queryByA11yValue', 'queryByAccessibilityValue'], - queryAllBy: ['queryAllByA11yValue', 'queryAllByAccessibilityValue'], - findBy: ['findByA11yValue', 'findByAccessibilityValue'], - findAllBy: ['findAllByA11yValue', 'findAllByAccessibilityValue'], - }, - matchObject - )(instance), - } as any); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts new file mode 100644 index 000000000..19133fd2c --- /dev/null +++ b/src/queries/a11yState.ts @@ -0,0 +1,77 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { AccessibilityState } from 'react-native'; +import { matchObjectProp } from '../helpers/matchers/matchObjectProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +const queryAllByA11yState = ( + instance: ReactTestInstance +): ((state: AccessibilityState) => Array) => + function queryAllByA11yStateFn(state) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchObjectProp(node.props.accessibilityState, state) + ); + }; + +const getMultipleError = (state: AccessibilityState) => + `Found multiple elements with accessibilityState: ${JSON.stringify(state)}`; +const getMissingError = (state: AccessibilityState) => + `Unable to find an element with accessibilityState: ${JSON.stringify(state)}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByA11yState, + getMissingError, + getMultipleError +); + +export type ByA11yStateQueries = { + getByA11yState: GetByQuery; + getAllByA11yState: GetAllByQuery; + queryByA11yState: QueryByQuery; + queryAllByA11yState: QueryAllByQuery; + findByA11yState: FindByQuery; + findAllByA11yState: FindAllByQuery; + + getByAccessibilityState: GetByQuery; + getAllByAccessibilityState: GetAllByQuery; + queryByAccessibilityState: QueryByQuery; + queryAllByAccessibilityState: QueryAllByQuery; + findByAccessibilityState: FindByQuery; + findAllByAccessibilityState: FindAllByQuery; +}; + +export const bindByA11yStateQueries = ( + instance: ReactTestInstance +): ByA11yStateQueries => { + const getByA11yState = getBy(instance); + const getAllByA11yState = getAllBy(instance); + const queryByA11yState = queryBy(instance); + const queryAllByA11yState = queryAllBy(instance); + const findByA11yState = findBy(instance); + const findAllByA11yState = findAllBy(instance); + + return { + getByA11yState, + getAllByA11yState, + queryByA11yState, + queryAllByA11yState, + findByA11yState, + findAllByA11yState, + + getByAccessibilityState: getByA11yState, + getAllByAccessibilityState: getAllByA11yState, + queryByAccessibilityState: queryByA11yState, + queryAllByAccessibilityState: queryAllByA11yState, + findByAccessibilityState: findByA11yState, + findAllByAccessibilityState: findAllByA11yState, + }; +}; diff --git a/src/queries/a11yStates.ts b/src/queries/a11yStates.ts new file mode 100644 index 000000000..fbceaa357 --- /dev/null +++ b/src/queries/a11yStates.ts @@ -0,0 +1,86 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { AccessibilityState } from 'react-native'; +import { matchArrayProp } from '../helpers/matchers/matchArrayProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +type AccessibilityStateKey = keyof AccessibilityState; +type AccessibilityStateKeys = + | AccessibilityStateKey + | Array; + +const queryAllByA11yStates = ( + instance: ReactTestInstance +): (( + accessibilityStates: AccessibilityStateKeys +) => Array) => + function queryAllByA11yStatesFn(accessibilityStates) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchArrayProp(node.props.accessibilityState, accessibilityStates) + ); + }; + +const getMultipleError = (states: AccessibilityStateKeys) => + `Found multiple elements with accessibilityState: ${JSON.stringify(states)}`; +const getMissingError = (states: AccessibilityStateKeys) => + `Unable to find an element with accessibilityState: ${JSON.stringify( + states + )}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByA11yStates, + getMissingError, + getMultipleError +); + +export type ByA11yStatesQueries = { + getByA11yStates: GetByQuery; + getAllByA11yStates: GetAllByQuery; + queryByA11yStates: QueryByQuery; + queryAllByA11yStates: QueryAllByQuery; + findByA11yStates: FindByQuery; + findAllByA11yStates: FindAllByQuery; + + getByAccessibilityStates: GetByQuery; + getAllByAccessibilityStates: GetAllByQuery; + queryByAccessibilityStates: QueryByQuery; + queryAllByAccessibilityStates: QueryAllByQuery; + findByAccessibilityStates: FindByQuery; + findAllByAccessibilityStates: FindAllByQuery; +}; + +export const bindByA11yStatesQueries = ( + instance: ReactTestInstance +): ByA11yStatesQueries => { + const getByA11yStates = getBy(instance); + const getAllByA11yStates = getAllBy(instance); + const queryByA11yStates = queryBy(instance); + const queryAllByA11yStates = queryAllBy(instance); + const findByA11yStates = findBy(instance); + const findAllByA11yStates = findAllBy(instance); + + return { + getByA11yStates, + getAllByA11yStates, + queryByA11yStates, + queryAllByA11yStates, + findByA11yStates, + findAllByA11yStates, + + getByAccessibilityStates: getByA11yStates, + getAllByAccessibilityStates: getAllByA11yStates, + queryByAccessibilityStates: queryByA11yStates, + queryAllByAccessibilityStates: queryAllByA11yStates, + findByAccessibilityStates: findByA11yStates, + findAllByAccessibilityStates: findAllByA11yStates, + }; +}; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts new file mode 100644 index 000000000..8e68957e3 --- /dev/null +++ b/src/queries/a11yValue.ts @@ -0,0 +1,83 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { matchObjectProp } from '../helpers/matchers/matchObjectProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +type A11yValue = { + min?: number; + max?: number; + now?: number; + text?: string; +}; + +const queryAllByA11yValue = ( + instance: ReactTestInstance +): ((value: A11yValue) => Array) => + function queryAllByA11yValueFn(value) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchObjectProp(node.props.accessibilityValue, value) + ); + }; + +const getMultipleError = (value: A11yValue) => + `Found multiple elements with accessibilityValue: ${JSON.stringify(value)} `; +const getMissingError = (value: A11yValue) => + `Unable to find an element with accessibilityValue: ${JSON.stringify(value)}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByA11yValue, + getMissingError, + getMultipleError +); + +export type ByA11yValueQueries = { + getByA11yValue: GetByQuery; + getAllByA11yValue: GetAllByQuery; + queryByA11yValue: QueryByQuery; + queryAllByA11yValue: QueryAllByQuery; + findByA11yValue: FindByQuery; + findAllByA11yValue: FindAllByQuery; + + getByAccessibilityValue: GetByQuery; + getAllByAccessibilityValue: GetAllByQuery; + queryByAccessibilityValue: QueryByQuery; + queryAllByAccessibilityValue: QueryAllByQuery; + findByAccessibilityValue: FindByQuery; + findAllByAccessibilityValue: FindAllByQuery; +}; + +export const bindByA11yValueQueries = ( + instance: ReactTestInstance +): ByA11yValueQueries => { + const getByA11yValue = getBy(instance); + const getAllByA11yValue = getAllBy(instance); + const queryByA11yValue = queryBy(instance); + const queryAllByA11yValue = queryAllBy(instance); + const findByA11yValue = findBy(instance); + const findAllByA11yValue = findAllBy(instance); + + return { + getByA11yValue, + getAllByA11yValue, + queryByA11yValue, + queryAllByA11yValue, + findByA11yValue, + findAllByA11yValue, + + getByAccessibilityValue: getByA11yValue, + getAllByAccessibilityValue: getAllByA11yValue, + queryByAccessibilityValue: queryByA11yValue, + queryAllByAccessibilityValue: queryAllByA11yValue, + findByAccessibilityValue: findByA11yValue, + findAllByAccessibilityValue: findAllByA11yValue, + }; +}; diff --git a/src/queries/hintText.ts b/src/queries/hintText.ts new file mode 100644 index 000000000..a7a28c1cc --- /dev/null +++ b/src/queries/hintText.ts @@ -0,0 +1,95 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { TextMatch } from '../matches'; +import { matchStringProp } from '../helpers/matchers/matchStringProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +const queryAllByHintText = ( + instance: ReactTestInstance +): ((hint: TextMatch) => Array) => + function queryAllByA11yHintFn(hint) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchStringProp(node.props.accessibilityHint, hint) + ); + }; + +const getMultipleError = (hint: TextMatch) => + `Found multiple elements with accessibilityHint: ${String(hint)} `; +const getMissingError = (hint: TextMatch) => + `Unable to find an element with accessibilityHint: ${String(hint)}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByHintText, + getMissingError, + getMultipleError +); + +export type ByHintTextQueries = { + getByHintText: GetByQuery; + getAllByHintText: GetAllByQuery; + queryByHintText: QueryByQuery; + queryAllByHintText: QueryAllByQuery; + findByHintText: FindByQuery; + findAllByHintText: FindAllByQuery; + + // a11yHint aliases + getByA11yHint: GetByQuery; + getAllByA11yHint: GetAllByQuery; + queryByA11yHint: QueryByQuery; + queryAllByA11yHint: QueryAllByQuery; + findByA11yHint: FindByQuery; + findAllByA11yHint: FindAllByQuery; + + // accessibilityHint aliases + getByAccessibilityHint: GetByQuery; + getAllByAccessibilityHint: GetAllByQuery; + queryByAccessibilityHint: QueryByQuery; + queryAllByAccessibilityHint: QueryAllByQuery; + findByAccessibilityHint: FindByQuery; + findAllByAccessibilityHint: FindAllByQuery; +}; + +export const bindByHintTextQueries = ( + instance: ReactTestInstance +): ByHintTextQueries => { + const getByHintText = getBy(instance); + const getAllByHintText = getAllBy(instance); + const queryByHintText = queryBy(instance); + const queryAllByHintText = queryAllBy(instance); + const findByHintText = findBy(instance); + const findAllByHintText = findAllBy(instance); + + return { + getByHintText, + getAllByHintText, + queryByHintText, + queryAllByHintText, + findByHintText, + findAllByHintText, + + // a11yHint aliases + getByA11yHint: getByHintText, + getAllByA11yHint: getAllByHintText, + queryByA11yHint: queryByHintText, + queryAllByA11yHint: queryAllByHintText, + findByA11yHint: findByHintText, + findAllByA11yHint: findAllByHintText, + + // accessibilityHint aliases + getByAccessibilityHint: getByHintText, + getAllByAccessibilityHint: getAllByHintText, + queryByAccessibilityHint: queryByHintText, + queryAllByAccessibilityHint: queryAllByHintText, + findByAccessibilityHint: findByHintText, + findAllByAccessibilityHint: findAllByHintText, + }; +}; diff --git a/src/queries/labelText.ts b/src/queries/labelText.ts new file mode 100644 index 000000000..8142222bb --- /dev/null +++ b/src/queries/labelText.ts @@ -0,0 +1,54 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { TextMatch } from '../matches'; +import { matchStringProp } from '../helpers/matchers/matchStringProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +const queryAllByLabelText = ( + instance: ReactTestInstance +): ((text: TextMatch) => Array) => + function queryAllByLabelTextFn(text) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchStringProp(node.props.accessibilityLabel, text) + ); + }; + +const getMultipleError = (labelText: TextMatch) => + `Found multiple elements with accessibilityLabel: ${String(labelText)} `; +const getMissingError = (labelText: TextMatch) => + `Unable to find an element with accessibilityLabel: ${String(labelText)}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByLabelText, + getMissingError, + getMultipleError +); + +export type ByLabelTextQueries = { + getByLabelText: GetByQuery; + getAllByLabelText: GetAllByQuery; + queryByLabelText: QueryByQuery; + queryAllByLabelText: QueryAllByQuery; + findByLabelText: FindByQuery; + findAllByLabelText: FindAllByQuery; +}; + +export const bindByLabelTextQueries = ( + instance: ReactTestInstance +): ByLabelTextQueries => ({ + getByLabelText: getBy(instance), + getAllByLabelText: getAllBy(instance), + queryByLabelText: queryBy(instance), + queryAllByLabelText: queryAllBy(instance), + findByLabelText: findBy(instance), + findAllByLabelText: findAllBy(instance), +}); diff --git a/src/queries/makeA11yQuery.ts b/src/queries/makeA11yQuery.ts deleted file mode 100644 index 889f00be8..000000000 --- a/src/queries/makeA11yQuery.ts +++ /dev/null @@ -1,96 +0,0 @@ -import type { ReactTestInstance } from 'react-test-renderer'; -import waitFor from '../waitFor'; -import type { WaitForOptions } from '../waitFor'; -import { - ErrorWithStack, - prepareErrorMessage, - createQueryByError, -} from '../helpers/errors'; - -function isNodeValid(node: ReactTestInstance) { - return typeof node.type === 'string'; -} - -function makeAliases(aliases: Array, query: Function) { - return aliases - .map((alias) => ({ [alias]: query })) - .reduce((acc, query) => ({ ...acc, ...query }), {}); -} - -type QueryNames = { - getBy: Array; - getAllBy: Array; - queryBy: Array; - queryAllBy: Array; - findBy: Array; - findAllBy: Array; -}; - -const makeA11yQuery =

( - name: string, - queryNames: QueryNames, - matcherFn: (prop: P, value: M) => boolean -) => (instance: ReactTestInstance) => { - const getBy = (matcher: M) => { - try { - return instance.find( - (node) => isNodeValid(node) && matcherFn(node.props[name], matcher) - ); - } catch (error) { - throw new ErrorWithStack( - prepareErrorMessage(error, name, matcher), - getBy - ); - } - }; - - const getAllBy = (matcher: M) => { - const results = instance.findAll( - (node) => isNodeValid(node) && matcherFn(node.props[name], matcher) - ); - - if (results.length === 0) { - throw new ErrorWithStack( - prepareErrorMessage(new Error('No instances found'), name, matcher), - getAllBy - ); - } - - return results; - }; - - const queryBy = (matcher: M) => { - try { - return getBy(matcher); - } catch (error) { - return createQueryByError(error, queryBy); - } - }; - - const queryAllBy = (matcher: M) => { - try { - return getAllBy(matcher); - } catch (error) { - return []; - } - }; - - const findBy = (matcher: M, waitForOptions?: WaitForOptions) => { - return waitFor(() => getBy(matcher), waitForOptions); - }; - - const findAllBy = (matcher: M, waitForOptions?: WaitForOptions) => { - return waitFor(() => getAllBy(matcher), waitForOptions); - }; - - return { - ...makeAliases(queryNames.getBy, getBy), - ...makeAliases(queryNames.getAllBy, getAllBy), - ...makeAliases(queryNames.queryBy, queryBy), - ...makeAliases(queryNames.queryAllBy, queryAllBy), - ...makeAliases(queryNames.findBy, findBy), - ...makeAliases(queryNames.findAllBy, findAllBy), - }; -}; - -export default makeA11yQuery; diff --git a/src/queries/makeQueries.ts b/src/queries/makeQueries.ts index b54da4207..0122259ab 100644 --- a/src/queries/makeQueries.ts +++ b/src/queries/makeQueries.ts @@ -3,33 +3,33 @@ import { ErrorWithStack } from '../helpers/errors'; import waitFor from '../waitFor'; import type { WaitForOptions } from '../waitFor'; -export type GetByQuery = ( +export type GetByQuery = ( predicate: Predicate, options?: Options ) => ReactTestInstance; -export type GetAllByQuery = ( +export type GetAllByQuery = ( predicate: Predicate, options?: Options ) => ReactTestInstance[]; -export type QueryByQuery = ( +export type QueryByQuery = ( predicate: Predicate, options?: Options ) => ReactTestInstance | null; -export type QueryAllByQuery = ( +export type QueryAllByQuery = ( predicate: Predicate, options?: Options ) => ReactTestInstance[]; -export type FindByQuery = ( +export type FindByQuery = ( predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions ) => Promise; -export type FindAllByQuery = ( +export type FindAllByQuery = ( predicate: Predicate, options?: Options & WaitForOptions, waitForOptions?: WaitForOptions diff --git a/src/queries/role.ts b/src/queries/role.ts new file mode 100644 index 000000000..552998b22 --- /dev/null +++ b/src/queries/role.ts @@ -0,0 +1,54 @@ +import type { ReactTestInstance } from 'react-test-renderer'; +import { TextMatch } from '../matches'; +import { matchStringProp } from '../helpers/matchers/matchStringProp'; +import { makeQueries } from './makeQueries'; +import type { + FindAllByQuery, + FindByQuery, + GetAllByQuery, + GetByQuery, + QueryAllByQuery, + QueryByQuery, +} from './makeQueries'; + +const queryAllByRole = ( + instance: ReactTestInstance +): ((role: TextMatch) => Array) => + function queryAllByRoleFn(role) { + return instance.findAll( + (node) => + typeof node.type === 'string' && + matchStringProp(node.props.accessibilityRole, role) + ); + }; + +const getMultipleError = (role: TextMatch) => + `Found multiple elements with accessibilityRole: ${String(role)} `; +const getMissingError = (role: TextMatch) => + `Unable to find an element with accessibilityRole: ${String(role)}`; + +const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries( + queryAllByRole, + getMissingError, + getMultipleError +); + +export type ByRoleQueries = { + getByRole: GetByQuery; + getAllByRole: GetAllByQuery; + queryByRole: QueryByQuery; + queryAllByRole: QueryAllByQuery; + findByRole: FindByQuery; + findAllByRole: FindAllByQuery; +}; + +export const bindByRoleQueries = ( + instance: ReactTestInstance +): ByRoleQueries => ({ + getByRole: getBy(instance), + getAllByRole: getAllBy(instance), + queryByRole: queryBy(instance), + queryAllByRole: queryAllBy(instance), + findByRole: findBy(instance), + findAllByRole: findAllBy(instance), +}); diff --git a/src/screen.ts b/src/screen.ts index 6d44957e4..5ce85f98d 100644 --- a/src/screen.ts +++ b/src/screen.ts @@ -27,18 +27,24 @@ const defaultScreen: RenderResult = { queryAllByLabelText: notImplemented, findByLabelText: notImplemented, findAllByLabelText: notImplemented, - getByA11yHint: notImplemented, getByHintText: notImplemented, - getAllByA11yHint: notImplemented, getAllByHintText: notImplemented, - queryByA11yHint: notImplemented, queryByHintText: notImplemented, - queryAllByA11yHint: notImplemented, queryAllByHintText: notImplemented, - findByA11yHint: notImplemented, findByHintText: notImplemented, - findAllByA11yHint: notImplemented, findAllByHintText: notImplemented, + getByA11yHint: notImplemented, + getAllByA11yHint: notImplemented, + queryByA11yHint: notImplemented, + queryAllByA11yHint: notImplemented, + findByA11yHint: notImplemented, + findAllByA11yHint: notImplemented, + getByAccessibilityHint: notImplemented, + getAllByAccessibilityHint: notImplemented, + queryByAccessibilityHint: notImplemented, + queryAllByAccessibilityHint: notImplemented, + findByAccessibilityHint: notImplemented, + findAllByAccessibilityHint: notImplemented, getByRole: notImplemented, getAllByRole: notImplemented, queryByRole: notImplemented, @@ -51,18 +57,36 @@ const defaultScreen: RenderResult = { queryAllByA11yStates: notImplemented, findByA11yStates: notImplemented, findAllByA11yStates: notImplemented, + getByAccessibilityStates: notImplemented, + getAllByAccessibilityStates: notImplemented, + queryByAccessibilityStates: notImplemented, + queryAllByAccessibilityStates: notImplemented, + findByAccessibilityStates: notImplemented, + findAllByAccessibilityStates: notImplemented, getByA11yState: notImplemented, getAllByA11yState: notImplemented, queryByA11yState: notImplemented, queryAllByA11yState: notImplemented, findByA11yState: notImplemented, findAllByA11yState: notImplemented, + getByAccessibilityState: notImplemented, + getAllByAccessibilityState: notImplemented, + queryByAccessibilityState: notImplemented, + queryAllByAccessibilityState: notImplemented, + findByAccessibilityState: notImplemented, + findAllByAccessibilityState: notImplemented, getByA11yValue: notImplemented, getAllByA11yValue: notImplemented, queryByA11yValue: notImplemented, queryAllByA11yValue: notImplemented, findByA11yValue: notImplemented, findAllByA11yValue: notImplemented, + getByAccessibilityValue: notImplemented, + getAllByAccessibilityValue: notImplemented, + queryByAccessibilityValue: notImplemented, + queryAllByAccessibilityValue: notImplemented, + findByAccessibilityValue: notImplemented, + findAllByAccessibilityValue: notImplemented, UNSAFE_getByProps: notImplemented, UNSAFE_getAllByProps: notImplemented, UNSAFE_queryByProps: notImplemented, diff --git a/src/within.ts b/src/within.ts index 9a6bdc8fe..e76122202 100644 --- a/src/within.ts +++ b/src/within.ts @@ -1,9 +1,14 @@ import type { ReactTestInstance } from 'react-test-renderer'; -import { a11yAPI } from './queries/a11yAPI'; import { bindByTextQueries } from './queries/text'; import { bindByTestIdQueries } from './queries/testId'; import { bindByDisplayValueQueries } from './queries/displayValue'; import { bindByPlaceholderTextQueries } from './queries/placeholderText'; +import { bindByLabelTextQueries } from './queries/labelText'; +import { bindByHintTextQueries } from './queries/hintText'; +import { bindByRoleQueries } from './queries/role'; +import { bindByA11yStateQueries } from './queries/a11yState'; +import { bindByA11yStatesQueries } from './queries/a11yStates'; +import { bindByA11yValueQueries } from './queries/a11yValue'; import { bindUnsafeByTypeQueries } from './queries/unsafeType'; import { bindUnsafeByPropsQueries } from './queries/unsafeProps'; @@ -13,9 +18,14 @@ export function within(instance: ReactTestInstance) { ...bindByTestIdQueries(instance), ...bindByDisplayValueQueries(instance), ...bindByPlaceholderTextQueries(instance), + ...bindByLabelTextQueries(instance), + ...bindByHintTextQueries(instance), + ...bindByRoleQueries(instance), + ...bindByA11yStateQueries(instance), + ...bindByA11yStatesQueries(instance), + ...bindByA11yValueQueries(instance), ...bindUnsafeByTypeQueries(instance), ...bindUnsafeByPropsQueries(instance), - ...a11yAPI(instance), }; }