From 206d562114e55ef10c4f04c0a8e0ff66eab73d88 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Tue, 15 Nov 2022 22:10:00 +0100 Subject: [PATCH 01/11] refactor: add deprecation messages to *ByA11yState and *ByA11yValue --- src/helpers/deprecation.ts | 33 ++++++++++ src/queries/__tests__/a11yState.test.tsx | 77 ++++++++++++++++++++++++ src/queries/__tests__/a11yValue.test.tsx | 77 ++++++++++++++++++++++++ src/queries/a11yState.ts | 37 ++++++++---- src/queries/a11yValue.ts | 37 ++++++++---- 5 files changed, 237 insertions(+), 24 deletions(-) create mode 100644 src/helpers/deprecation.ts diff --git a/src/helpers/deprecation.ts b/src/helpers/deprecation.ts new file mode 100644 index 000000000..7abf792b5 --- /dev/null +++ b/src/helpers/deprecation.ts @@ -0,0 +1,33 @@ +export function deprecateAllQueries>( + queriesObject: Queries, + querySuffix: string, + recommendationSuffix: string +): Queries { + const result = {} as Queries; + Object.keys(queriesObject).forEach((queryName) => { + const queryFn = queriesObject[queryName]; + const recommendation = queryName.replace(querySuffix, recommendationSuffix); + // @ts-expect-error: generic typing is hard + result[queryName] = deprecateQuery(queryFn, queryName, recommendation); + }); + + return result; +} + +export function deprecateQuery any>( + queryFn: QueryFn, + queryName: string, + recommendation: string +): QueryFn { + // @ts-expect-error: generic typing is hard + const wrapper: QueryFn = (...args: any) => { + // eslint-disable-next-line no-console + console.warn( + `${queryName}(...) is deprecated. Please use ${recommendation} instead.` + ); + + return queryFn(...args); + }; + + return wrapper; +} diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index 7c9f94f45..b778da58e 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -1,7 +1,14 @@ +/* eslint-disable no-console */ import * as React from 'react'; import { View, Text, Pressable, TouchableOpacity } from 'react-native'; import { render } from '../..'; +type ConsoleLogMock = jest.Mock; + +beforeEach(() => { + jest.spyOn(console, 'warn').mockImplementation(() => {}); +}); + const TEXT_LABEL = 'cool text'; const Typography = ({ children, ...rest }: any) => { @@ -251,3 +258,73 @@ test('byA11yState queries support hidden option', () => { `"Unable to find an element with expanded state: false"` ); }); + +test('*ByA11yState deprecation warnings', () => { + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; + const view = render(); + + view.getByA11yState({ disabled: true }); + expect(mockCalls[0][0]).toMatchInlineSnapshot( + `"getByA11yState(...) is deprecated. Please use getByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.getAllByA11yState({ disabled: true }); + expect(mockCalls[1][0]).toMatchInlineSnapshot( + `"getAllByA11yState(...) is deprecated. Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.queryByA11yState({ disabled: true }); + expect(mockCalls[2][0]).toMatchInlineSnapshot( + `"queryByA11yState(...) is deprecated. Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.queryAllByA11yState({ disabled: true }); + expect(mockCalls[3][0]).toMatchInlineSnapshot( + `"queryAllByA11yState(...) is deprecated. Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.findByA11yState({ disabled: true }); + expect(mockCalls[4][0]).toMatchInlineSnapshot( + `"findByA11yState(...) is deprecated. Please use findByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.findAllByA11yState({ disabled: true }); + expect(mockCalls[5][0]).toMatchInlineSnapshot( + `"findAllByA11yState(...) is deprecated. Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); +}); + +test('*ByAccessibilityState deprecation warnings', () => { + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; + const view = render(); + + view.getByAccessibilityState({ disabled: true }); + expect(mockCalls[0][0]).toMatchInlineSnapshot( + `"getByAccessibilityState(...) is deprecated. Please use getByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.getAllByAccessibilityState({ disabled: true }); + expect(mockCalls[1][0]).toMatchInlineSnapshot( + `"getAllByAccessibilityState(...) is deprecated. Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.queryByAccessibilityState({ disabled: true }); + expect(mockCalls[2][0]).toMatchInlineSnapshot( + `"queryByAccessibilityState(...) is deprecated. Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.queryAllByAccessibilityState({ disabled: true }); + expect(mockCalls[3][0]).toMatchInlineSnapshot( + `"queryAllByAccessibilityState(...) is deprecated. Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.findByAccessibilityState({ disabled: true }); + expect(mockCalls[4][0]).toMatchInlineSnapshot( + `"findByAccessibilityState(...) is deprecated. Please use findByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); + + view.findAllByAccessibilityState({ disabled: true }); + expect(mockCalls[5][0]).toMatchInlineSnapshot( + `"findAllByAccessibilityState(...) is deprecated. Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` + ); +}); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index d77b9aa4e..e7da9bd1c 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -1,7 +1,14 @@ +/* eslint-disable no-console */ import * as React from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { render } from '../..'; +type ConsoleLogMock = jest.Mock; + +beforeEach(() => { + jest.spyOn(console, 'warn').mockImplementation(() => {}); +}); + const TEXT_LABEL = 'cool text'; const Typography = ({ children, ...rest }: any) => { @@ -130,3 +137,73 @@ test('byA11yValue error messages', () => { `"Unable to find an element with min value: 1, max value: 2, now value: 3, text value: /foo/i"` ); }); + +test('*ByA11yValue deprecation warnings', () => { + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; + const view = render(); + + view.getByA11yValue({ min: 10 }); + expect(mockCalls[0][0]).toMatchInlineSnapshot( + `"getByA11yValue(...) is deprecated. Please use getByRole(role, { value: ... }) instead."` + ); + + view.getAllByA11yValue({ min: 10 }); + expect(mockCalls[1][0]).toMatchInlineSnapshot( + `"getAllByA11yValue(...) is deprecated. Please use getAllByRole(role, { value: ... }) instead."` + ); + + view.queryByA11yValue({ min: 10 }); + expect(mockCalls[2][0]).toMatchInlineSnapshot( + `"queryByA11yValue(...) is deprecated. Please use queryByRole(role, { value: ... }) instead."` + ); + + view.queryAllByA11yValue({ min: 10 }); + expect(mockCalls[3][0]).toMatchInlineSnapshot( + `"queryAllByA11yValue(...) is deprecated. Please use queryAllByRole(role, { value: ... }) instead."` + ); + + view.findByA11yValue({ min: 10 }); + expect(mockCalls[4][0]).toMatchInlineSnapshot( + `"findByA11yValue(...) is deprecated. Please use findByRole(role, { value: ... }) instead."` + ); + + view.findAllByA11yValue({ min: 10 }); + expect(mockCalls[5][0]).toMatchInlineSnapshot( + `"findAllByA11yValue(...) is deprecated. Please use findAllByRole(role, { value: ... }) instead."` + ); +}); + +test('*ByAccessibilityValue deprecation warnings', () => { + const mockCalls = (console.warn as ConsoleLogMock).mock.calls; + const view = render(); + + view.getByAccessibilityValue({ min: 10 }); + expect(mockCalls[0][0]).toMatchInlineSnapshot( + `"getByAccessibilityValue(...) is deprecated. Please use getByRole(role, { value: ... }) instead."` + ); + + view.getAllByAccessibilityValue({ min: 10 }); + expect(mockCalls[1][0]).toMatchInlineSnapshot( + `"getAllByAccessibilityValue(...) is deprecated. Please use getAllByRole(role, { value: ... }) instead."` + ); + + view.queryByAccessibilityValue({ min: 10 }); + expect(mockCalls[2][0]).toMatchInlineSnapshot( + `"queryByAccessibilityValue(...) is deprecated. Please use queryByRole(role, { value: ... }) instead."` + ); + + view.queryAllByAccessibilityValue({ min: 10 }); + expect(mockCalls[3][0]).toMatchInlineSnapshot( + `"queryAllByAccessibilityValue(...) is deprecated. Please use queryAllByRole(role, { value: ... }) instead."` + ); + + view.findByAccessibilityValue({ min: 10 }); + expect(mockCalls[4][0]).toMatchInlineSnapshot( + `"findByAccessibilityValue(...) is deprecated. Please use findByRole(role, { value: ... }) instead."` + ); + + view.findAllByAccessibilityValue({ min: 10 }); + expect(mockCalls[5][0]).toMatchInlineSnapshot( + `"findAllByAccessibilityValue(...) is deprecated. Please use findAllByRole(role, { value: ... }) instead."` + ); +}); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index 84ca4bcb9..b211b3859 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -1,6 +1,7 @@ import type { ReactTestInstance } from 'react-test-renderer'; import { AccessibilityState } from 'react-native'; import { accessibilityStateKeys } from '../helpers/accessiblity'; +import { deprecateAllQueries } from '../helpers/deprecation'; import { findAll } from '../helpers/findAll'; import { matchAccessibilityState } from '../helpers/matchers/accessibilityState'; import { makeQueries } from './makeQueries'; @@ -92,18 +93,30 @@ export const bindByA11yStateQueries = ( const findAllByA11yState = findAllBy(instance); return { - getByA11yState, - getAllByA11yState, - queryByA11yState, - queryAllByA11yState, - findByA11yState, - findAllByA11yState, + ...deprecateAllQueries( + { + getByA11yState, + getAllByA11yState, + queryByA11yState, + queryAllByA11yState, + findByA11yState, + findAllByA11yState, + }, + 'A11yState', + 'Role(role, { disabled, selected, checked, busy, expanded })' + ), - getByAccessibilityState: getByA11yState, - getAllByAccessibilityState: getAllByA11yState, - queryByAccessibilityState: queryByA11yState, - queryAllByAccessibilityState: queryAllByA11yState, - findByAccessibilityState: findByA11yState, - findAllByAccessibilityState: findAllByA11yState, + ...deprecateAllQueries( + { + getByAccessibilityState: getByA11yState, + getAllByAccessibilityState: getAllByA11yState, + queryByAccessibilityState: queryByA11yState, + queryAllByAccessibilityState: queryAllByA11yState, + findByAccessibilityState: findByA11yState, + findAllByAccessibilityState: findAllByA11yState, + }, + 'AccessibilityState', + 'Role(role, { disabled, selected, checked, busy, expanded })' + ), }; }; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index a7273094a..45c6c9cdc 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -1,5 +1,6 @@ import type { ReactTestInstance } from 'react-test-renderer'; import { accessiblityValueKeys } from '../helpers/accessiblity'; +import { deprecateAllQueries } from '../helpers/deprecation'; import { findAll } from '../helpers/findAll'; import { AccessibilityValueMatcher, @@ -109,18 +110,30 @@ export const bindByA11yValueQueries = ( const findAllByA11yValue = findAllBy(instance); return { - getByA11yValue, - getAllByA11yValue, - queryByA11yValue, - queryAllByA11yValue, - findByA11yValue, - findAllByA11yValue, + ...deprecateAllQueries( + { + getByA11yValue, + getAllByA11yValue, + queryByA11yValue, + queryAllByA11yValue, + findByA11yValue, + findAllByA11yValue, + }, + 'A11yValue', + 'Role(role, { value: ... })' + ), - getByAccessibilityValue: getByA11yValue, - getAllByAccessibilityValue: getAllByA11yValue, - queryByAccessibilityValue: queryByA11yValue, - queryAllByAccessibilityValue: queryAllByA11yValue, - findByAccessibilityValue: findByA11yValue, - findAllByAccessibilityValue: findAllByA11yValue, + ...deprecateAllQueries( + { + getByAccessibilityValue: getByA11yValue, + getAllByAccessibilityValue: getAllByA11yValue, + queryByAccessibilityValue: queryByA11yValue, + queryAllByAccessibilityValue: queryAllByA11yValue, + findByAccessibilityValue: findByA11yValue, + findAllByAccessibilityValue: findAllByA11yValue, + }, + 'AccessibilityValue', + 'Role(role, { value: ... })' + ), }; }; From fa19a84dd01f653a0fc3df755ce2091ef5dbd414 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Tue, 15 Nov 2022 22:25:08 +0100 Subject: [PATCH 02/11] chore: tweak deprecating messages --- src/helpers/deprecation.ts | 2 +- src/queries/__tests__/a11yState.test.tsx | 108 +++++++++++++++-------- src/queries/__tests__/a11yValue.test.tsx | 96 ++++++++++++-------- src/queries/a11yState.ts | 4 +- 4 files changed, 135 insertions(+), 75 deletions(-) diff --git a/src/helpers/deprecation.ts b/src/helpers/deprecation.ts index 7abf792b5..fe5bdee23 100644 --- a/src/helpers/deprecation.ts +++ b/src/helpers/deprecation.ts @@ -23,7 +23,7 @@ export function deprecateQuery any>( const wrapper: QueryFn = (...args: any) => { // eslint-disable-next-line no-console console.warn( - `${queryName}(...) is deprecated. Please use ${recommendation} instead.` + `${queryName}(...) is deprecated.\n\nPlease use ${recommendation} instead.` ); return queryFn(...args); diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index b778da58e..d133704dd 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -264,34 +264,52 @@ test('*ByA11yState deprecation warnings', () => { const view = render(); view.getByA11yState({ disabled: true }); - expect(mockCalls[0][0]).toMatchInlineSnapshot( - `"getByA11yState(...) is deprecated. Please use getByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[0][0]).toMatchInlineSnapshot(` + "getByA11yState(...) is deprecated. + + Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.getAllByA11yState({ disabled: true }); - expect(mockCalls[1][0]).toMatchInlineSnapshot( - `"getAllByA11yState(...) is deprecated. Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[1][0]).toMatchInlineSnapshot(` + "getAllByA11yState(...) is deprecated. + + Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.queryByA11yState({ disabled: true }); - expect(mockCalls[2][0]).toMatchInlineSnapshot( - `"queryByA11yState(...) is deprecated. Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[2][0]).toMatchInlineSnapshot(` + "queryByA11yState(...) is deprecated. + + Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.queryAllByA11yState({ disabled: true }); - expect(mockCalls[3][0]).toMatchInlineSnapshot( - `"queryAllByA11yState(...) is deprecated. Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[3][0]).toMatchInlineSnapshot(` + "queryAllByA11yState(...) is deprecated. + + Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.findByA11yState({ disabled: true }); - expect(mockCalls[4][0]).toMatchInlineSnapshot( - `"findByA11yState(...) is deprecated. Please use findByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[4][0]).toMatchInlineSnapshot(` + "findByA11yState(...) is deprecated. + + Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.findAllByA11yState({ disabled: true }); - expect(mockCalls[5][0]).toMatchInlineSnapshot( - `"findAllByA11yState(...) is deprecated. Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[5][0]).toMatchInlineSnapshot(` + "findAllByA11yState(...) is deprecated. + + Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); }); test('*ByAccessibilityState deprecation warnings', () => { @@ -299,32 +317,50 @@ test('*ByAccessibilityState deprecation warnings', () => { const view = render(); view.getByAccessibilityState({ disabled: true }); - expect(mockCalls[0][0]).toMatchInlineSnapshot( - `"getByAccessibilityState(...) is deprecated. Please use getByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[0][0]).toMatchInlineSnapshot(` + "getByAccessibilityState(...) is deprecated. + + Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.getAllByAccessibilityState({ disabled: true }); - expect(mockCalls[1][0]).toMatchInlineSnapshot( - `"getAllByAccessibilityState(...) is deprecated. Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[1][0]).toMatchInlineSnapshot(` + "getAllByAccessibilityState(...) is deprecated. + + Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.queryByAccessibilityState({ disabled: true }); - expect(mockCalls[2][0]).toMatchInlineSnapshot( - `"queryByAccessibilityState(...) is deprecated. Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[2][0]).toMatchInlineSnapshot(` + "queryByAccessibilityState(...) is deprecated. + + Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.queryAllByAccessibilityState({ disabled: true }); - expect(mockCalls[3][0]).toMatchInlineSnapshot( - `"queryAllByAccessibilityState(...) is deprecated. Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[3][0]).toMatchInlineSnapshot(` + "queryAllByAccessibilityState(...) is deprecated. + + Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.findByAccessibilityState({ disabled: true }); - expect(mockCalls[4][0]).toMatchInlineSnapshot( - `"findByAccessibilityState(...) is deprecated. Please use findByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[4][0]).toMatchInlineSnapshot(` + "findByAccessibilityState(...) is deprecated. + + Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); view.findAllByAccessibilityState({ disabled: true }); - expect(mockCalls[5][0]).toMatchInlineSnapshot( - `"findAllByAccessibilityState(...) is deprecated. Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) instead."` - ); + expect(mockCalls[5][0]).toMatchInlineSnapshot(` + "findAllByAccessibilityState(...) is deprecated. + + Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query + or expect(...).toHaveAccessibilityState(...) matcher instead." + `); }); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index e7da9bd1c..6b8a0b16a 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -143,34 +143,46 @@ test('*ByA11yValue deprecation warnings', () => { const view = render(); view.getByA11yValue({ min: 10 }); - expect(mockCalls[0][0]).toMatchInlineSnapshot( - `"getByA11yValue(...) is deprecated. Please use getByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[0][0]).toMatchInlineSnapshot(` + "getByA11yValue(...) is deprecated. + + Please use getByRole(role, { value: ... }) instead." + `); view.getAllByA11yValue({ min: 10 }); - expect(mockCalls[1][0]).toMatchInlineSnapshot( - `"getAllByA11yValue(...) is deprecated. Please use getAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[1][0]).toMatchInlineSnapshot(` + "getAllByA11yValue(...) is deprecated. + + Please use getAllByRole(role, { value: ... }) instead." + `); view.queryByA11yValue({ min: 10 }); - expect(mockCalls[2][0]).toMatchInlineSnapshot( - `"queryByA11yValue(...) is deprecated. Please use queryByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[2][0]).toMatchInlineSnapshot(` + "queryByA11yValue(...) is deprecated. + + Please use queryByRole(role, { value: ... }) instead." + `); view.queryAllByA11yValue({ min: 10 }); - expect(mockCalls[3][0]).toMatchInlineSnapshot( - `"queryAllByA11yValue(...) is deprecated. Please use queryAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[3][0]).toMatchInlineSnapshot(` + "queryAllByA11yValue(...) is deprecated. + + Please use queryAllByRole(role, { value: ... }) instead." + `); view.findByA11yValue({ min: 10 }); - expect(mockCalls[4][0]).toMatchInlineSnapshot( - `"findByA11yValue(...) is deprecated. Please use findByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[4][0]).toMatchInlineSnapshot(` + "findByA11yValue(...) is deprecated. + + Please use findByRole(role, { value: ... }) instead." + `); view.findAllByA11yValue({ min: 10 }); - expect(mockCalls[5][0]).toMatchInlineSnapshot( - `"findAllByA11yValue(...) is deprecated. Please use findAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[5][0]).toMatchInlineSnapshot(` + "findAllByA11yValue(...) is deprecated. + + Please use findAllByRole(role, { value: ... }) instead." + `); }); test('*ByAccessibilityValue deprecation warnings', () => { @@ -178,32 +190,44 @@ test('*ByAccessibilityValue deprecation warnings', () => { const view = render(); view.getByAccessibilityValue({ min: 10 }); - expect(mockCalls[0][0]).toMatchInlineSnapshot( - `"getByAccessibilityValue(...) is deprecated. Please use getByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[0][0]).toMatchInlineSnapshot(` + "getByAccessibilityValue(...) is deprecated. + + Please use getByRole(role, { value: ... }) instead." + `); view.getAllByAccessibilityValue({ min: 10 }); - expect(mockCalls[1][0]).toMatchInlineSnapshot( - `"getAllByAccessibilityValue(...) is deprecated. Please use getAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[1][0]).toMatchInlineSnapshot(` + "getAllByAccessibilityValue(...) is deprecated. + + Please use getAllByRole(role, { value: ... }) instead." + `); view.queryByAccessibilityValue({ min: 10 }); - expect(mockCalls[2][0]).toMatchInlineSnapshot( - `"queryByAccessibilityValue(...) is deprecated. Please use queryByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[2][0]).toMatchInlineSnapshot(` + "queryByAccessibilityValue(...) is deprecated. + + Please use queryByRole(role, { value: ... }) instead." + `); view.queryAllByAccessibilityValue({ min: 10 }); - expect(mockCalls[3][0]).toMatchInlineSnapshot( - `"queryAllByAccessibilityValue(...) is deprecated. Please use queryAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[3][0]).toMatchInlineSnapshot(` + "queryAllByAccessibilityValue(...) is deprecated. + + Please use queryAllByRole(role, { value: ... }) instead." + `); view.findByAccessibilityValue({ min: 10 }); - expect(mockCalls[4][0]).toMatchInlineSnapshot( - `"findByAccessibilityValue(...) is deprecated. Please use findByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[4][0]).toMatchInlineSnapshot(` + "findByAccessibilityValue(...) is deprecated. + + Please use findByRole(role, { value: ... }) instead." + `); view.findAllByAccessibilityValue({ min: 10 }); - expect(mockCalls[5][0]).toMatchInlineSnapshot( - `"findAllByAccessibilityValue(...) is deprecated. Please use findAllByRole(role, { value: ... }) instead."` - ); + expect(mockCalls[5][0]).toMatchInlineSnapshot(` + "findAllByAccessibilityValue(...) is deprecated. + + Please use findAllByRole(role, { value: ... }) instead." + `); }); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index b211b3859..dd92dc22e 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -103,7 +103,7 @@ export const bindByA11yStateQueries = ( findAllByA11yState, }, 'A11yState', - 'Role(role, { disabled, selected, checked, busy, expanded })' + 'Role(role, { disabled, selected, checked, busy, expanded }) query\nor expect(...).toHaveAccessibilityState(...) matcher' ), ...deprecateAllQueries( @@ -116,7 +116,7 @@ export const bindByA11yStateQueries = ( findAllByAccessibilityState: findAllByA11yState, }, 'AccessibilityState', - 'Role(role, { disabled, selected, checked, busy, expanded })' + 'Role(role, { disabled, selected, checked, busy, expanded }) query\nor expect(...).toHaveAccessibilityState(...) matcher' ), }; }; From ff6aac84ff3d43a40c88dd35f9d192e524d91fa2 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 16 Nov 2022 11:10:56 +0100 Subject: [PATCH 03/11] chore: tweak deprecation warnings --- src/queries/__tests__/a11yState.test.tsx | 36 ++++++++---------------- src/queries/__tests__/a11yValue.test.tsx | 24 ++++++++-------- src/queries/a11yState.ts | 4 +-- src/queries/a11yValue.ts | 4 +-- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index d133704dd..72a40933d 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -267,48 +267,42 @@ test('*ByA11yState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yState(...) is deprecated. - Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByA11yState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yState(...) is deprecated. - Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByA11yState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yState(...) is deprecated. - Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByA11yState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yState(...) is deprecated. - Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByA11yState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yState(...) is deprecated. - Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByA11yState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yState(...) is deprecated. - Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); }); @@ -320,47 +314,41 @@ test('*ByAccessibilityState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityState(...) is deprecated. - Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByAccessibilityState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityState(...) is deprecated. - Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByAccessibilityState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityState(...) is deprecated. - Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByAccessibilityState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityState(...) is deprecated. - Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByAccessibilityState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityState(...) is deprecated. - Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByAccessibilityState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityState(...) is deprecated. - Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query - or expect(...).toHaveAccessibilityState(...) matcher instead." + Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); }); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index 6b8a0b16a..f52a1bd1a 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -146,42 +146,42 @@ test('*ByA11yValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yValue(...) is deprecated. - Please use getByRole(role, { value: ... }) instead." + Please use getByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.getAllByA11yValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yValue(...) is deprecated. - Please use getAllByRole(role, { value: ... }) instead." + Please use getAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.queryByA11yValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yValue(...) is deprecated. - Please use queryByRole(role, { value: ... }) instead." + Please use queryByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.queryAllByA11yValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yValue(...) is deprecated. - Please use queryAllByRole(role, { value: ... }) instead." + Please use queryAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.findByA11yValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yValue(...) is deprecated. - Please use findByRole(role, { value: ... }) instead." + Please use findByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.findAllByA11yValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yValue(...) is deprecated. - Please use findAllByRole(role, { value: ... }) instead." + Please use findAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); }); @@ -193,41 +193,41 @@ test('*ByAccessibilityValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityValue(...) is deprecated. - Please use getByRole(role, { value: ... }) instead." + Please use getByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.getAllByAccessibilityValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityValue(...) is deprecated. - Please use getAllByRole(role, { value: ... }) instead." + Please use getAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.queryByAccessibilityValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityValue(...) is deprecated. - Please use queryByRole(role, { value: ... }) instead." + Please use queryByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.queryAllByAccessibilityValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityValue(...) is deprecated. - Please use queryAllByRole(role, { value: ... }) instead." + Please use queryAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.findByAccessibilityValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityValue(...) is deprecated. - Please use findByRole(role, { value: ... }) instead." + Please use findByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); view.findAllByAccessibilityValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityValue(...) is deprecated. - Please use findAllByRole(role, { value: ... }) instead." + Please use findAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." `); }); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index dd92dc22e..f879d750d 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -103,7 +103,7 @@ export const bindByA11yStateQueries = ( findAllByA11yState, }, 'A11yState', - 'Role(role, { disabled, selected, checked, busy, expanded }) query\nor expect(...).toHaveAccessibilityState(...) matcher' + 'Role(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher' ), ...deprecateAllQueries( @@ -116,7 +116,7 @@ export const bindByA11yStateQueries = ( findAllByAccessibilityState: findAllByA11yState, }, 'AccessibilityState', - 'Role(role, { disabled, selected, checked, busy, expanded }) query\nor expect(...).toHaveAccessibilityState(...) matcher' + 'Role(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher' ), }; }; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index 45c6c9cdc..139d27e76 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -120,7 +120,7 @@ export const bindByA11yValueQueries = ( findAllByA11yValue, }, 'A11yValue', - 'Role(role, { value: ... })' + 'Role(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher' ), ...deprecateAllQueries( @@ -133,7 +133,7 @@ export const bindByA11yValueQueries = ( findAllByAccessibilityValue: findAllByA11yValue, }, 'AccessibilityValue', - 'Role(role, { value: ... })' + 'Role(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher' ), }; }; From df0cc8b34defef1b4fb732e6c680665655347056 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 16 Nov 2022 11:18:39 +0100 Subject: [PATCH 04/11] docs: add deprecation message --- website/docs/API.md | 4 ++-- website/docs/Queries.md | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/website/docs/API.md b/website/docs/API.md index 4b779fbd8..719cf602f 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -685,7 +685,7 @@ Use cases for scoped queries include: ## `query` APIs -Each of the get APIs listed in the render section above have a complimentary query API. The get APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the hierarchy, then you can use the query API instead: +Each of the `getBy` APIs listed in the render section above have a complimentary `queryBy` API. The `getBy` APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the hierarchy, then you can use the `queryBy` API instead: ```jsx import { render, screen } from '@testing-library/react-native'; @@ -697,7 +697,7 @@ expect(submitButton).not.toBeOnTheScreen(); // it doesn't exist ## `queryAll` APIs -Each of the query APIs have a corresponding queryAll version that always returns an Array of matching nodes. getAll is the same but throws when the array has a length of 0. +Each of the query APIs have a corresponding `queryAll` version that always returns an array of matching nodes. `getAll` is the same but throws when the array has a length of 0. ```jsx import { render } from '@testing-library/react-native'; diff --git a/website/docs/Queries.md b/website/docs/Queries.md index ddacabeac..6f26478ff 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -22,10 +22,10 @@ title: Queries - [`ByHintText`, `ByA11yHint`, `ByAccessibilityHint`](#byhinttext-bya11yhint-byaccessibilityhint) - [`ByRole`](#byrole) - [Options](#options-1) - - [`ByA11yState`, `ByAccessibilityState`](#bya11ystate-byaccessibilitystate) + - [`ByA11yState`, `ByAccessibilityState` (deprecated)](#bya11ystate-byaccessibilitystate-deprecated) - [Default state for: `disabled`, `selected`, and `busy` keys](#default-state-for-disabled-selected-and-busy-keys) - [Default state for: `checked` and `expanded` keys](#default-state-for-checked-and-expanded-keys) - - [`ByA11Value`, `ByAccessibilityValue`](#bya11value-byaccessibilityvalue) + - [`ByA11Value`, `ByAccessibilityValue` (deprecated)](#bya11value-byaccessibilityvalue-deprecated) - [Common options](#common-options) - [`includeHiddenElements` option](#includehiddenelements-option) - [TextMatch](#textmatch) @@ -309,7 +309,11 @@ const element3 = screen.getByRole('button', { name: 'Hello', disabled: true }); `value`: Filter elements by their accessibility, available value entries include numeric `min`, `max` & `now`, as well as string or regex `text` key. See React Native [accessibilityValue](https://reactnative.dev/docs/accessibility#accessibilityvalue) docs to learn more about this prop. -### `ByA11yState`, `ByAccessibilityState` +### `ByA11yState`, `ByAccessibilityState` (deprecated) + +:::caution +This method has been marked deprecated, as similar functionallity can be better achieved using [`*ByRole`](#byrole) query with state options (`disabled`, `selected`, etc) or by using [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher. +::: :::caution This query uses a predicate that is typically too general to give meaningful results. Therefore, it's better to use one of the following options: @@ -372,7 +376,11 @@ but will not match elements with following props: The difference in handling default values is made to reflect observed accessibility behaviour on iOS and Android platforms. ::: -### `ByA11Value`, `ByAccessibilityValue` +### `ByA11Value`, `ByAccessibilityValue` (deprecated) + +:::caution +This method has been marked deprecated, as similar functionallity can be better achieved using [`*ByRole`](#byrole) query with `value` option or by using [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher. +::: :::caution This query uses a predicate that is typically too general to give meaningful results. Therefore, it's better to use one of the following options: From 2078fa55082fdacd67acbe54e6f9238cd17b3bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 10:55:23 +0000 Subject: [PATCH 05/11] refactor: improve code readability and structure --- src/helpers/__tests__/query-name.test.ts | 10 ++++++++++ src/helpers/deprecation.ts | 17 ++++++++++------- src/helpers/query-name.ts | 4 ++++ src/queries/__tests__/a11yState.test.tsx | 24 ++++++++++++------------ src/queries/__tests__/a11yValue.test.tsx | 24 ++++++++++++------------ src/queries/a11yState.ts | 10 +--------- src/queries/a11yValue.ts | 10 +--------- 7 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 src/helpers/__tests__/query-name.test.ts create mode 100644 src/helpers/query-name.ts diff --git a/src/helpers/__tests__/query-name.test.ts b/src/helpers/__tests__/query-name.test.ts new file mode 100644 index 000000000..3ef7b9529 --- /dev/null +++ b/src/helpers/__tests__/query-name.test.ts @@ -0,0 +1,10 @@ +import { getQueryPrefix } from '../query-name'; + +test('getQueryPrefix should return correct prefix', () => { + expect(getQueryPrefix('getByRole')).toBe('get'); + expect(getQueryPrefix('getAllByText')).toEqual('getAll'); + expect(getQueryPrefix('queryByTestId')).toEqual('query'); + expect(getQueryPrefix('queryAllByPlaceholderText')).toEqual('queryAll'); + expect(getQueryPrefix('findByHintText')).toEqual('find'); + expect(getQueryPrefix('findAllByDisplayValue')).toEqual('findAll'); +}); diff --git a/src/helpers/deprecation.ts b/src/helpers/deprecation.ts index fe5bdee23..48fd8473d 100644 --- a/src/helpers/deprecation.ts +++ b/src/helpers/deprecation.ts @@ -1,12 +1,12 @@ +import { getQueryPrefix } from './query-name'; + export function deprecateAllQueries>( queriesObject: Queries, - querySuffix: string, - recommendationSuffix: string + recommendation: string ): Queries { const result = {} as Queries; Object.keys(queriesObject).forEach((queryName) => { const queryFn = queriesObject[queryName]; - const recommendation = queryName.replace(querySuffix, recommendationSuffix); // @ts-expect-error: generic typing is hard result[queryName] = deprecateQuery(queryFn, queryName, recommendation); }); @@ -19,13 +19,16 @@ export function deprecateQuery any>( queryName: string, recommendation: string ): QueryFn { + const formattedRecommendation = recommendation.replace( + /{queryPrefix}/g, + getQueryPrefix(queryName) + ); + // @ts-expect-error: generic typing is hard const wrapper: QueryFn = (...args: any) => { + const errorMessage = `${queryName}(...) is deprecated.\n\n${formattedRecommendation}`; // eslint-disable-next-line no-console - console.warn( - `${queryName}(...) is deprecated.\n\nPlease use ${recommendation} instead.` - ); - + console.warn(errorMessage); return queryFn(...args); }; diff --git a/src/helpers/query-name.ts b/src/helpers/query-name.ts new file mode 100644 index 000000000..1a6a034c8 --- /dev/null +++ b/src/helpers/query-name.ts @@ -0,0 +1,4 @@ +export function getQueryPrefix(queryName: string) { + const parts = queryName.split('By'); + return parts[0]; +} diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index 72a40933d..e0ee6c8f4 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -267,42 +267,42 @@ test('*ByA11yState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yState(...) is deprecated. - Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByA11yState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yState(...) is deprecated. - Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByA11yState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yState(...) is deprecated. - Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByA11yState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yState(...) is deprecated. - Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByA11yState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yState(...) is deprecated. - Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByA11yState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yState(...) is deprecated. - Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); }); @@ -314,41 +314,41 @@ test('*ByAccessibilityState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityState(...) is deprecated. - Please use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByAccessibilityState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityState(...) is deprecated. - Please use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByAccessibilityState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityState(...) is deprecated. - Please use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByAccessibilityState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityState(...) is deprecated. - Please use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByAccessibilityState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityState(...) is deprecated. - Please use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByAccessibilityState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityState(...) is deprecated. - Please use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); }); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index f52a1bd1a..e5a477b5f 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -146,42 +146,42 @@ test('*ByA11yValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yValue(...) is deprecated. - Please use getByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." `); view.getAllByA11yValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yValue(...) is deprecated. - Please use getAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." `); view.queryByA11yValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yValue(...) is deprecated. - Please use queryByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." `); view.queryAllByA11yValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yValue(...) is deprecated. - Please use queryAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." `); view.findByA11yValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yValue(...) is deprecated. - Please use findByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." `); view.findAllByA11yValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yValue(...) is deprecated. - Please use findAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." `); }); @@ -193,41 +193,41 @@ test('*ByAccessibilityValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityValue(...) is deprecated. - Please use getByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." `); view.getAllByAccessibilityValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityValue(...) is deprecated. - Please use getAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." `); view.queryByAccessibilityValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityValue(...) is deprecated. - Please use queryByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." `); view.queryAllByAccessibilityValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityValue(...) is deprecated. - Please use queryAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." `); view.findByAccessibilityValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityValue(...) is deprecated. - Please use findByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." `); view.findAllByAccessibilityValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityValue(...) is deprecated. - Please use findAllByRole(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher instead." + Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." `); }); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index f879d750d..655ea5d56 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -101,13 +101,6 @@ export const bindByA11yStateQueries = ( queryAllByA11yState, findByA11yState, findAllByA11yState, - }, - 'A11yState', - 'Role(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher' - ), - - ...deprecateAllQueries( - { getByAccessibilityState: getByA11yState, getAllByAccessibilityState: getAllByA11yState, queryByAccessibilityState: queryByA11yState, @@ -115,8 +108,7 @@ export const bindByA11yStateQueries = ( findByAccessibilityState: findByA11yState, findAllByAccessibilityState: findAllByA11yState, }, - 'AccessibilityState', - 'Role(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher' + 'Use {queryPrefix}ByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead.' ), }; }; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index 139d27e76..085d6d1cb 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -118,13 +118,6 @@ export const bindByA11yValueQueries = ( queryAllByA11yValue, findByA11yValue, findAllByA11yValue, - }, - 'A11yValue', - 'Role(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher' - ), - - ...deprecateAllQueries( - { getByAccessibilityValue: getByA11yValue, getAllByAccessibilityValue: getAllByA11yValue, queryByAccessibilityValue: queryByA11yValue, @@ -132,8 +125,7 @@ export const bindByA11yValueQueries = ( findByAccessibilityValue: findByA11yValue, findAllByAccessibilityValue: findAllByA11yValue, }, - 'AccessibilityValue', - 'Role(role, { value: ... }) query or expect(...).toHaveAccessibilityValue(...) matcher' + 'Use expect(...).toHaveAccessibilityValue(...) matcher or {queryPrefix}ByRole(role, { value: ... }) query instead.' ), }; }; From 68265e325eb7789bcb8df626454de1d11e13513e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 13:26:20 +0000 Subject: [PATCH 06/11] refactor: code review changes --- src/helpers/deprecation.ts | 6 +++--- src/queries/__tests__/a11yState.test.tsx | 24 ++++++++++++------------ src/queries/__tests__/a11yValue.test.tsx | 24 ++++++++++++------------ src/queries/a11yState.ts | 4 ++-- src/queries/a11yValue.ts | 4 ++-- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/helpers/deprecation.ts b/src/helpers/deprecation.ts index 48fd8473d..80c51325d 100644 --- a/src/helpers/deprecation.ts +++ b/src/helpers/deprecation.ts @@ -1,6 +1,6 @@ import { getQueryPrefix } from './query-name'; -export function deprecateAllQueries>( +export function deprecateQueries>( queriesObject: Queries, recommendation: string ): Queries { @@ -14,7 +14,7 @@ export function deprecateAllQueries>( return result; } -export function deprecateQuery any>( +function deprecateQuery any>( queryFn: QueryFn, queryName: string, recommendation: string @@ -26,7 +26,7 @@ export function deprecateQuery any>( // @ts-expect-error: generic typing is hard const wrapper: QueryFn = (...args: any) => { - const errorMessage = `${queryName}(...) is deprecated.\n\n${formattedRecommendation}`; + const errorMessage = `${queryName}(...) is deprecated and will be removed in the future.\n\n${formattedRecommendation}`; // eslint-disable-next-line no-console console.warn(errorMessage); return queryFn(...args); diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index e0ee6c8f4..1021b0d18 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -265,42 +265,42 @@ test('*ByA11yState deprecation warnings', () => { view.getByA11yState({ disabled: true }); expect(mockCalls[0][0]).toMatchInlineSnapshot(` - "getByA11yState(...) is deprecated. + "getByA11yState(...) is deprecated and will be removed in the future. Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByA11yState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` - "getAllByA11yState(...) is deprecated. + "getAllByA11yState(...) is deprecated and will be removed in the future. Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByA11yState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` - "queryByA11yState(...) is deprecated. + "queryByA11yState(...) is deprecated and will be removed in the future. Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByA11yState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` - "queryAllByA11yState(...) is deprecated. + "queryAllByA11yState(...) is deprecated and will be removed in the future. Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByA11yState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` - "findByA11yState(...) is deprecated. + "findByA11yState(...) is deprecated and will be removed in the future. Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByA11yState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` - "findAllByA11yState(...) is deprecated. + "findAllByA11yState(...) is deprecated and will be removed in the future. Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); @@ -312,42 +312,42 @@ test('*ByAccessibilityState deprecation warnings', () => { view.getByAccessibilityState({ disabled: true }); expect(mockCalls[0][0]).toMatchInlineSnapshot(` - "getByAccessibilityState(...) is deprecated. + "getByAccessibilityState(...) is deprecated and will be removed in the future. Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.getAllByAccessibilityState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` - "getAllByAccessibilityState(...) is deprecated. + "getAllByAccessibilityState(...) is deprecated and will be removed in the future. Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryByAccessibilityState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` - "queryByAccessibilityState(...) is deprecated. + "queryByAccessibilityState(...) is deprecated and will be removed in the future. Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.queryAllByAccessibilityState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` - "queryAllByAccessibilityState(...) is deprecated. + "queryAllByAccessibilityState(...) is deprecated and will be removed in the future. Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findByAccessibilityState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` - "findByAccessibilityState(...) is deprecated. + "findByAccessibilityState(...) is deprecated and will be removed in the future. Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); view.findAllByAccessibilityState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` - "findAllByAccessibilityState(...) is deprecated. + "findAllByAccessibilityState(...) is deprecated and will be removed in the future. Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." `); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index e5a477b5f..75c5dbd4e 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -144,42 +144,42 @@ test('*ByA11yValue deprecation warnings', () => { view.getByA11yValue({ min: 10 }); expect(mockCalls[0][0]).toMatchInlineSnapshot(` - "getByA11yValue(...) is deprecated. + "getByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." `); view.getAllByA11yValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` - "getAllByA11yValue(...) is deprecated. + "getAllByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." `); view.queryByA11yValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` - "queryByA11yValue(...) is deprecated. + "queryByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." `); view.queryAllByA11yValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` - "queryAllByA11yValue(...) is deprecated. + "queryAllByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." `); view.findByA11yValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` - "findByA11yValue(...) is deprecated. + "findByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." `); view.findAllByA11yValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` - "findAllByA11yValue(...) is deprecated. + "findAllByA11yValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." `); @@ -191,42 +191,42 @@ test('*ByAccessibilityValue deprecation warnings', () => { view.getByAccessibilityValue({ min: 10 }); expect(mockCalls[0][0]).toMatchInlineSnapshot(` - "getByAccessibilityValue(...) is deprecated. + "getByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." `); view.getAllByAccessibilityValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` - "getAllByAccessibilityValue(...) is deprecated. + "getAllByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." `); view.queryByAccessibilityValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` - "queryByAccessibilityValue(...) is deprecated. + "queryByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." `); view.queryAllByAccessibilityValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` - "queryAllByAccessibilityValue(...) is deprecated. + "queryAllByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." `); view.findByAccessibilityValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` - "findByAccessibilityValue(...) is deprecated. + "findByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." `); view.findAllByAccessibilityValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` - "findAllByAccessibilityValue(...) is deprecated. + "findAllByAccessibilityValue(...) is deprecated and will be removed in the future. Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." `); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index 655ea5d56..917135641 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -1,7 +1,7 @@ import type { ReactTestInstance } from 'react-test-renderer'; import { AccessibilityState } from 'react-native'; import { accessibilityStateKeys } from '../helpers/accessiblity'; -import { deprecateAllQueries } from '../helpers/deprecation'; +import { deprecateQueries } from '../helpers/deprecation'; import { findAll } from '../helpers/findAll'; import { matchAccessibilityState } from '../helpers/matchers/accessibilityState'; import { makeQueries } from './makeQueries'; @@ -93,7 +93,7 @@ export const bindByA11yStateQueries = ( const findAllByA11yState = findAllBy(instance); return { - ...deprecateAllQueries( + ...deprecateQueries( { getByA11yState, getAllByA11yState, diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index 085d6d1cb..f1b3dd4dc 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -1,6 +1,6 @@ import type { ReactTestInstance } from 'react-test-renderer'; import { accessiblityValueKeys } from '../helpers/accessiblity'; -import { deprecateAllQueries } from '../helpers/deprecation'; +import { deprecateQueries } from '../helpers/deprecation'; import { findAll } from '../helpers/findAll'; import { AccessibilityValueMatcher, @@ -110,7 +110,7 @@ export const bindByA11yValueQueries = ( const findAllByA11yValue = findAllBy(instance); return { - ...deprecateAllQueries( + ...deprecateQueries( { getByA11yValue, getAllByA11yValue, From eae615af927462e480119c0e2675871399ce0edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 13:34:24 +0000 Subject: [PATCH 07/11] docs: merge duplicate deprecation entries --- website/docs/Queries.md | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 6f26478ff..6636d190a 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -312,13 +312,9 @@ const element3 = screen.getByRole('button', { name: 'Hello', disabled: true }); ### `ByA11yState`, `ByAccessibilityState` (deprecated) :::caution -This method has been marked deprecated, as similar functionallity can be better achieved using [`*ByRole`](#byrole) query with state options (`disabled`, `selected`, etc) or by using [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher. -::: - -:::caution -This query uses a predicate that is typically too general to give meaningful results. Therefore, it's better to use one of the following options: -* use one of [`ByRole`](#byrole) queries with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` -* use [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) matcher to check the state of element found using some other query +This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of the following options: +* [`*ByRole`](#byrole) query with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` +* [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher to check the state of element found using some other query. ::: > getByA11yState, getAllByA11yState, queryByA11yState, queryAllByA11yState, findByA11yState, findAllByA11yState @@ -379,16 +375,11 @@ The difference in handling default values is made to reflect observed accessibil ### `ByA11Value`, `ByAccessibilityValue` (deprecated) :::caution -This method has been marked deprecated, as similar functionallity can be better achieved using [`*ByRole`](#byrole) query with `value` option or by using [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher. +This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of the following options: +* [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query. +* [`*ByRole`](#byrole) query with `value` option ::: -:::caution -This query uses a predicate that is typically too general to give meaningful results. Therefore, it's better to use one of the following options: -* use one of [`ByRole`](#byrole) queries with `value` option -* use [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) matcher to check the state of element found using some other query -::: - - > getByA11yValue, getAllByA11yValue, queryByA11yValue, queryAllByA11yValue, findByA11yValue, findAllByA11yValue > getByAccessibilityValue, getAllByAccessibilityValue, queryByAccessibilityValue, queryAllByAccessibilityValue, findByAccessibilityValue, findAllByAccessibilityValue From 8b5327fc46f879eb7aee82c262256ae1404fa20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 13:36:23 +0000 Subject: [PATCH 08/11] refactor: improve error messages --- src/queries/__tests__/a11yState.test.tsx | 24 ++++++++++++------------ src/queries/__tests__/a11yValue.test.tsx | 24 ++++++++++++------------ src/queries/a11yState.ts | 2 +- src/queries/a11yValue.ts | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index 1021b0d18..2ad522967 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -267,42 +267,42 @@ test('*ByA11yState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yState(...) is deprecated and will be removed in the future. - Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.getAllByA11yState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yState(...) is deprecated and will be removed in the future. - Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.queryByA11yState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yState(...) is deprecated and will be removed in the future. - Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.queryAllByA11yState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yState(...) is deprecated and will be removed in the future. - Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.findByA11yState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yState(...) is deprecated and will be removed in the future. - Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.findAllByA11yState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yState(...) is deprecated and will be removed in the future. - Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); }); @@ -314,41 +314,41 @@ test('*ByAccessibilityState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityState(...) is deprecated and will be removed in the future. - Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.getAllByAccessibilityState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.queryByAccessibilityState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityState(...) is deprecated and will be removed in the future. - Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.queryAllByAccessibilityState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.findByAccessibilityState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityState(...) is deprecated and will be removed in the future. - Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); view.findAllByAccessibilityState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." `); }); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index 75c5dbd4e..26744787b 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -146,42 +146,42 @@ test('*ByA11yValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getByRole(role, { value: ... }) query instead." `); view.getAllByA11yValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getAllByRole(role, { value: ... }) query instead." `); view.queryByA11yValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryByRole(role, { value: ... }) query instead." `); view.queryAllByA11yValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryAllByRole(role, { value: ... }) query instead." `); view.findByA11yValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findByRole(role, { value: ... }) query instead." `); view.findAllByA11yValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findAllByRole(role, { value: ... }) query instead." `); }); @@ -193,41 +193,41 @@ test('*ByAccessibilityValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or getByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getByRole(role, { value: ... }) query instead." `); view.getAllByAccessibilityValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or getAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getAllByRole(role, { value: ... }) query instead." `); view.queryByAccessibilityValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or queryByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryByRole(role, { value: ... }) query instead." `); view.queryAllByAccessibilityValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or queryAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryAllByRole(role, { value: ... }) query instead." `); view.findByAccessibilityValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or findByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findByRole(role, { value: ... }) query instead." `); view.findAllByAccessibilityValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher or findAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findAllByRole(role, { value: ... }) query instead." `); }); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index 917135641..af5b5c692 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -108,7 +108,7 @@ export const bindByA11yStateQueries = ( findByAccessibilityState: findByA11yState, findAllByAccessibilityState: findAllByA11yState, }, - 'Use {queryPrefix}ByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher instead.' + 'Use {queryPrefix}ByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead.' ), }; }; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index f1b3dd4dc..ab2aac0db 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -125,7 +125,7 @@ export const bindByA11yValueQueries = ( findByAccessibilityValue: findByA11yValue, findAllByAccessibilityValue: findAllByA11yValue, }, - 'Use expect(...).toHaveAccessibilityValue(...) matcher or {queryPrefix}ByRole(role, { value: ... }) query instead.' + 'Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or {queryPrefix}ByRole(role, { value: ... }) query instead.' ), }; }; From ee9b10a81864793ccf801d5b43af8268ef49be6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 13:37:58 +0000 Subject: [PATCH 09/11] chore: fix typo --- src/queries/__tests__/a11yState.test.tsx | 24 ++++++++++++------------ src/queries/__tests__/a11yValue.test.tsx | 24 ++++++++++++------------ src/queries/a11yState.ts | 2 +- src/queries/a11yValue.ts | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/queries/__tests__/a11yState.test.tsx b/src/queries/__tests__/a11yState.test.tsx index 2ad522967..bb50ae2fa 100644 --- a/src/queries/__tests__/a11yState.test.tsx +++ b/src/queries/__tests__/a11yState.test.tsx @@ -267,42 +267,42 @@ test('*ByA11yState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yState(...) is deprecated and will be removed in the future. - Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.getAllByA11yState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yState(...) is deprecated and will be removed in the future. - Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.queryByA11yState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yState(...) is deprecated and will be removed in the future. - Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.queryAllByA11yState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yState(...) is deprecated and will be removed in the future. - Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.findByA11yState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yState(...) is deprecated and will be removed in the future. - Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.findAllByA11yState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yState(...) is deprecated and will be removed in the future. - Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); }); @@ -314,41 +314,41 @@ test('*ByAccessibilityState deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityState(...) is deprecated and will be removed in the future. - Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use getByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.getAllByAccessibilityState({ disabled: true }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use getAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.queryByAccessibilityState({ disabled: true }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityState(...) is deprecated and will be removed in the future. - Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use queryByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.queryAllByAccessibilityState({ disabled: true }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use queryAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.findByAccessibilityState({ disabled: true }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityState(...) is deprecated and will be removed in the future. - Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use findByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); view.findAllByAccessibilityState({ disabled: true }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityState(...) is deprecated and will be removed in the future. - Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead." + Use findAllByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead." `); }); diff --git a/src/queries/__tests__/a11yValue.test.tsx b/src/queries/__tests__/a11yValue.test.tsx index 26744787b..c713fc38d 100644 --- a/src/queries/__tests__/a11yValue.test.tsx +++ b/src/queries/__tests__/a11yValue.test.tsx @@ -146,42 +146,42 @@ test('*ByA11yValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or getByRole(role, { value: ... }) query instead." `); view.getAllByA11yValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or getAllByRole(role, { value: ... }) query instead." `); view.queryByA11yValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or queryByRole(role, { value: ... }) query instead." `); view.queryAllByA11yValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or queryAllByRole(role, { value: ... }) query instead." `); view.findByA11yValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or findByRole(role, { value: ... }) query instead." `); view.findAllByA11yValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByA11yValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or findAllByRole(role, { value: ... }) query instead." `); }); @@ -193,41 +193,41 @@ test('*ByAccessibilityValue deprecation warnings', () => { expect(mockCalls[0][0]).toMatchInlineSnapshot(` "getByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or getByRole(role, { value: ... }) query instead." `); view.getAllByAccessibilityValue({ min: 10 }); expect(mockCalls[1][0]).toMatchInlineSnapshot(` "getAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or getAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or getAllByRole(role, { value: ... }) query instead." `); view.queryByAccessibilityValue({ min: 10 }); expect(mockCalls[2][0]).toMatchInlineSnapshot(` "queryByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or queryByRole(role, { value: ... }) query instead." `); view.queryAllByAccessibilityValue({ min: 10 }); expect(mockCalls[3][0]).toMatchInlineSnapshot(` "queryAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or queryAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or queryAllByRole(role, { value: ... }) query instead." `); view.findByAccessibilityValue({ min: 10 }); expect(mockCalls[4][0]).toMatchInlineSnapshot(` "findByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or findByRole(role, { value: ... }) query instead." `); view.findAllByAccessibilityValue({ min: 10 }); expect(mockCalls[5][0]).toMatchInlineSnapshot(` "findAllByAccessibilityValue(...) is deprecated and will be removed in the future. - Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or findAllByRole(role, { value: ... }) query instead." + Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or findAllByRole(role, { value: ... }) query instead." `); }); diff --git a/src/queries/a11yState.ts b/src/queries/a11yState.ts index af5b5c692..1d7e64005 100644 --- a/src/queries/a11yState.ts +++ b/src/queries/a11yState.ts @@ -108,7 +108,7 @@ export const bindByA11yStateQueries = ( findByAccessibilityState: findByA11yState, findAllByAccessibilityState: findAllByA11yState, }, - 'Use {queryPrefix}ByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from @testing-library/jest-nativ package instead.' + 'Use {queryPrefix}ByRole(role, { disabled, selected, checked, busy, expanded }) query or expect(...).toHaveAccessibilityState(...) matcher from "@testing-library/jest-native" package instead.' ), }; }; diff --git a/src/queries/a11yValue.ts b/src/queries/a11yValue.ts index ab2aac0db..f77881cff 100644 --- a/src/queries/a11yValue.ts +++ b/src/queries/a11yValue.ts @@ -125,7 +125,7 @@ export const bindByA11yValueQueries = ( findByAccessibilityValue: findByA11yValue, findAllByAccessibilityValue: findAllByA11yValue, }, - 'Use expect(...).toHaveAccessibilityValue(...) matcher from @testing-library/jest-native package or {queryPrefix}ByRole(role, { value: ... }) query instead.' + 'Use expect(...).toHaveAccessibilityValue(...) matcher from "@testing-library/jest-native" package or {queryPrefix}ByRole(role, { value: ... }) query instead.' ), }; }; From f8c841d1ebad3f855443be952f9f3a5abb015729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Fri, 27 Jan 2023 13:39:23 +0000 Subject: [PATCH 10/11] docs: typos --- website/docs/Queries.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 6636d190a..46da384af 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -312,9 +312,9 @@ const element3 = screen.getByRole('button', { name: 'Hello', disabled: true }); ### `ByA11yState`, `ByAccessibilityState` (deprecated) :::caution -This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of the following options: +This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: * [`*ByRole`](#byrole) query with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` -* [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher to check the state of element found using some other query. +* [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher to check the state of element found using some other query ::: > getByA11yState, getAllByA11yState, queryByA11yState, queryAllByA11yState, findByA11yState, findAllByA11yState @@ -375,8 +375,8 @@ The difference in handling default values is made to reflect observed accessibil ### `ByA11Value`, `ByAccessibilityValue` (deprecated) :::caution -This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of the following options: -* [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query. +This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: +* [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query * [`*ByRole`](#byrole) query with `value` option ::: From 7ef644531ce1ad98ff710eab423c06f6a7f8c630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Sat, 28 Jan 2023 21:25:45 +0000 Subject: [PATCH 11/11] docs: tweaks --- website/docs/API.md | 14 +++++++------- website/docs/Queries.md | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/website/docs/API.md b/website/docs/API.md index 719cf602f..a859bd008 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -30,11 +30,11 @@ title: API - [On a `ScrollView`](#on-a-scrollview) - [On a `FlatList`](#on-a-flatlist) - [`waitFor`](#waitfor) - - [Using jest fake timers](#using-jest-fake-timers) + - [Using Jest fake timers](#using-jest-fake-timers) - [`waitForElementToBeRemoved`](#waitforelementtoberemoved) - [`within`, `getQueriesForElement`](#within-getqueriesforelement) -- [`query` APIs](#query-apis) -- [`queryAll` APIs](#queryall-apis) +- [`queryBy*` APIs](#queryby-apis) +- [`queryAll*` APIs](#queryall-apis) - [`act`](#act) - [`renderHook`](#renderhook) - [`callback`](#callback) @@ -683,9 +683,9 @@ Use cases for scoped queries include: - queries scoped to a single item inside a FlatList containing many items - queries scoped to a single screen in tests involving screen transitions (e.g. with react-navigation) -## `query` APIs +## `queryBy*` APIs -Each of the `getBy` APIs listed in the render section above have a complimentary `queryBy` API. The `getBy` APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the hierarchy, then you can use the `queryBy` API instead: +Each of the `getBy*` APIs listed in the render section above have a complimentary `queryBy*` API. The `getBy*` APIs will throw errors if a proper node cannot be found. This is normally the desired effect. However, if you want to make an assertion that an element is not present in the hierarchy, then you can use the `queryBy*` API instead: ```jsx import { render, screen } from '@testing-library/react-native'; @@ -695,9 +695,9 @@ const submitButton = screen.queryByText('submit'); expect(submitButton).not.toBeOnTheScreen(); // it doesn't exist ``` -## `queryAll` APIs +## `queryAll*` APIs -Each of the query APIs have a corresponding `queryAll` version that always returns an array of matching nodes. `getAll` is the same but throws when the array has a length of 0. +Each of the query APIs have a corresponding `queryAll*` version that always returns an array of matching nodes. `getAll*` is the same but throws when the array has a length of 0. ```jsx import { render } from '@testing-library/react-native'; diff --git a/website/docs/Queries.md b/website/docs/Queries.md index 46da384af..fa539ec48 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -312,7 +312,7 @@ const element3 = screen.getByRole('button', { name: 'Hello', disabled: true }); ### `ByA11yState`, `ByAccessibilityState` (deprecated) :::caution -This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: +This query has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: * [`*ByRole`](#byrole) query with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` * [`toHaveAccessibilityState()`](https://github.com/testing-library/jest-native#tohaveaccessibilitystate) Jest matcher to check the state of element found using some other query ::: @@ -375,7 +375,7 @@ The difference in handling default values is made to reflect observed accessibil ### `ByA11Value`, `ByAccessibilityValue` (deprecated) :::caution -This method has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: +This query has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: * [`toHaveAccessibilityValue()`](https://github.com/testing-library/jest-native#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query * [`*ByRole`](#byrole) query with `value` option ::: @@ -551,7 +551,7 @@ The interface is the same as for other queries, but we won't provide full names Returns a `ReactTestInstance` with matching a React component type. :::caution -This method has been marked unsafe, since it requires knowledge about implementation details of the component. Use responsibly. +This query has been marked unsafe, since it requires knowledge about implementation details of the component. Use responsibly. ::: ### `UNSAFE_ByProps` @@ -561,7 +561,7 @@ This method has been marked unsafe, since it requires knowledge about implementa Returns a `ReactTestInstance` with matching props object. :::caution -This method has been marked unsafe, since it requires knowledge about implementation details of the component. Use responsibly. +This query has been marked unsafe, since it requires knowledge about implementation details of the component. Use responsibly. :::