Feat(breaking): remove deprecated functions (#334)

* WIP

* More changes

* WIP

* Added throwRemovedFunctionError docsRef

* Fixed tests

* Typescript types cleanup

* Cleanup

* Moving some changes from `prepare-2` branch

* Moving some changes from `prepare-2` branch

* Update src/waitFor.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* Code review changes

* More code review changes

* Code review changes

* More code review changes

* Added @deprecated messages for TS type defs

* Spelling mistake

* Reformatted index.d.ts

* Removed remaining refs to warnFn

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
This commit is contained in:
Maciej Jastrzebski
2020-05-19 16:18:05 +02:00
committed by Michał Pierzchała
parent 163cc8533a
commit 9fc83fec60
16 changed files with 432 additions and 441 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ The [public API](https://callstack.github.io/react-native-testing-library/docs/a
## Migration Guides
- [Migration to 2.0](https://callstack.github.io/react-native-testing-library/docs/migration20)
- [Migration to 2.0](https://callstack.github.io/react-native-testing-library/docs/migration-v2)
## Made with ❤️ at Callstack
@@ -150,12 +150,12 @@ exports[`debug: shallow 1`] = `
underlineColorAndroid=\\"transparent\\"
value=\\"I inspected freshie\\"
/>
<Button
<MyButton
onPress={[Function anonymous]}
type=\\"primary\\"
>
Change freshness!
</Button>
</MyButton>
<Text
testID=\\"duplicateText\\"
>
@@ -200,12 +200,12 @@ exports[`debug: shallow with message 1`] = `
underlineColorAndroid=\\"transparent\\"
value=\\"I inspected freshie\\"
/>
<Button
<MyButton
onPress={[Function anonymous]}
type=\\"primary\\"
>
Change freshness!
</Button>
</MyButton>
<Text
testID=\\"duplicateText\\"
>
@@ -1,21 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`shallow rendering React Test Instance 1`] = `
<Text
testID="text-button"
>
Press me
</Text>
`;
exports[`shallow rendering React elements 1`] = `
<View
testID="2"
>
<Text
testID="text-button"
>
Press me
</Text>
</View>
`;
+26 -60
View File
@@ -17,7 +17,7 @@ const PLACEHOLDER_CHEF = 'Who inspected freshness?';
const INPUT_FRESHNESS = 'Custom Freshie';
const INPUT_CHEF = 'I inspected freshie';
class Button extends React.Component<any> {
class MyButton extends React.Component<any> {
render() {
return (
<TouchableOpacity onPress={this.props.onPress}>
@@ -68,9 +68,9 @@ class Banana extends React.Component<any, any> {
placeholder={PLACEHOLDER_CHEF}
value={INPUT_CHEF}
/>
<Button onPress={this.changeFresh} type="primary">
<MyButton onPress={this.changeFresh} type="primary">
Change freshness!
</Button>
</MyButton>
<Text testID="duplicateText">First Text</Text>
<Text testID="duplicateText">Second Text</Text>
<Text>{test}</Text>
@@ -109,51 +109,18 @@ test('getAllByTestId, queryAllByTestId', () => {
expect(queryAllByTestId('nonExistentTestId')).toHaveLength(0);
});
test('getByName, queryByName', () => {
const { getByText, getByName, queryByName } = render(<Banana />);
const bananaFresh = getByText('not fresh');
const button = getByName('Button');
button.props.onPress();
expect(bananaFresh.props.children).toBe('fresh');
const sameButton = getByName(Button);
sameButton.props.onPress();
expect(bananaFresh.props.children).toBe('not fresh');
expect(() => getByName('InExistent')).toThrow('No instances found');
expect(() => getByName(Text)).toThrow('Expected 1 but found 6');
expect(queryByName('Button')).toBe(button);
expect(queryByName('InExistent')).toBeNull();
});
test('getAllByName, queryAllByName', () => {
const { getAllByName, queryAllByName } = render(<Banana />);
const [text, status, button] = getAllByName('Text');
expect(text.props.children).toBe('Is the banana fresh?');
expect(status.props.children).toBe('not fresh');
expect(button.props.children).toBe('Change freshness!');
expect(() => getAllByName('InExistent')).toThrow('No instances found');
expect(queryAllByName('Text')[1]).toBe(status);
expect(queryAllByName('InExistent')).toHaveLength(0);
});
test('getAllByType, queryAllByType', () => {
const { getAllByType, queryAllByType } = render(<Banana />);
const [text, status, button] = getAllByType(Text);
test('UNSAFE_getAllByType, UNSAFE_queryAllByType', () => {
const { UNSAFE_getAllByType, UNSAFE_queryAllByType } = render(<Banana />);
const [text, status, button] = UNSAFE_getAllByType(Text);
const InExistent = () => null;
expect(text.props.children).toBe('Is the banana fresh?');
expect(status.props.children).toBe('not fresh');
expect(button.props.children).toBe('Change freshness!');
expect(() => getAllByType(InExistent)).toThrow('No instances found');
expect(() => UNSAFE_getAllByType(InExistent)).toThrow('No instances found');
expect(queryAllByType(Text)[1]).toBe(status);
expect(queryAllByType(InExistent)).toHaveLength(0);
expect(UNSAFE_queryAllByType(Text)[1]).toBe(status);
expect(UNSAFE_queryAllByType(InExistent)).toHaveLength(0);
});
test('getByText, queryByText', () => {
@@ -267,38 +234,37 @@ test('getAllByDisplayValue, queryAllByDisplayValue', () => {
expect(queryAllByDisplayValue('no value')).toHaveLength(0);
});
test('getByProps, queryByProps', () => {
const { getByProps, queryByProps } = render(<Banana />);
const primaryType = getByProps({ type: 'primary' });
test('UNSAFE_getByProps, UNSAFE_queryByProps', () => {
const { UNSAFE_getByProps, UNSAFE_queryByProps } = render(<Banana />);
const primaryType = UNSAFE_getByProps({ type: 'primary' });
expect(primaryType.props.children).toBe('Change freshness!');
expect(() => getByProps({ type: 'inexistent' })).toThrow(
expect(() => UNSAFE_getByProps({ type: 'inexistent' })).toThrow(
'No instances found'
);
expect(queryByProps({ type: 'primary' })).toBe(primaryType);
expect(queryByProps({ type: 'inexistent' })).toBeNull();
expect(UNSAFE_queryByProps({ type: 'primary' })).toBe(primaryType);
expect(UNSAFE_queryByProps({ type: 'inexistent' })).toBeNull();
});
test('getAllByProp, queryAllByProps', () => {
const { getAllByProps, queryAllByProps } = render(<Banana />);
const primaryTypes = getAllByProps({ type: 'primary' });
test('UNSAFE_getAllByProp, UNSAFE_queryAllByProps', () => {
const { UNSAFE_getAllByProps, UNSAFE_queryAllByProps } = render(<Banana />);
const primaryTypes = UNSAFE_getAllByProps({ type: 'primary' });
expect(primaryTypes).toHaveLength(1);
expect(() => getAllByProps({ type: 'inexistent' })).toThrow(
expect(() => UNSAFE_getAllByProps({ type: 'inexistent' })).toThrow(
'No instances found'
);
expect(queryAllByProps({ type: 'primary' })).toEqual(primaryTypes);
expect(queryAllByProps({ type: 'inexistent' })).toHaveLength(0);
expect(UNSAFE_queryAllByProps({ type: 'primary' })).toEqual(primaryTypes);
expect(UNSAFE_queryAllByProps({ type: 'inexistent' })).toHaveLength(0);
});
test('update', () => {
const fn = jest.fn();
const { getByName, update, rerender } = render(<Banana onUpdate={fn} />);
const button = getByName('Button');
const { getByText, update, rerender } = render(<Banana onUpdate={fn} />);
button.props.onPress();
fireEvent.press(getByText('Change freshness!'));
update(<Banana onUpdate={fn} />);
rerender(<Banana onUpdate={fn} />);
@@ -314,7 +280,7 @@ test('unmount', () => {
});
test('toJSON', () => {
const { toJSON } = render(<Button>press me</Button>);
const { toJSON } = render(<MyButton>press me</MyButton>);
expect(toJSON()).toMatchSnapshot();
});
@@ -345,9 +311,9 @@ test('debug', () => {
test('debug changing component', () => {
jest.spyOn(console, 'log').mockImplementation((x) => x);
const { getByProps, debug } = render(<Banana />);
const { UNSAFE_getByProps, debug } = render(<Banana />);
fireEvent.press(getByProps({ type: 'primary' }));
fireEvent.press(UNSAFE_getByProps({ type: 'primary' }));
debug();
-27
View File
@@ -1,27 +0,0 @@
// @flow
import React from 'react';
import { View, Text } from 'react-native';
import { shallow, render } from '..';
type Props = {|
+dummyID?: string,
|};
const TextPress = ({ dummyID }: Props) => (
<View testID={dummyID}>
<Text testID="text-button">Press me</Text>
</View>
);
test('shallow rendering React elements', () => {
const { output } = shallow(<TextPress dummyID="2" />);
expect(output).toMatchSnapshot();
});
test('shallow rendering React Test Instance', () => {
const { getByText } = render(<TextPress />);
const { output } = shallow(getByText('Press me'));
expect(output).toMatchSnapshot();
});
+4 -4
View File
@@ -36,9 +36,9 @@ class BananaContainer extends React.Component<{}, any> {
}
test('waits for element until it stops throwing', async () => {
const { getByText, getByName, queryByText } = render(<BananaContainer />);
const { getByText, queryByText } = render(<BananaContainer />);
fireEvent.press(getByName('TouchableOpacity'));
fireEvent.press(getByText('Change freshness!'));
expect(queryByText('Fresh')).toBeNull();
@@ -48,9 +48,9 @@ test('waits for element until it stops throwing', async () => {
});
test('waits for element until timeout is met', async () => {
const { getByText, getByName } = render(<BananaContainer />);
const { getByText } = render(<BananaContainer />);
fireEvent.press(getByName('TouchableOpacity'));
fireEvent.press(getByText('Change freshness!'));
await expect(
waitFor(() => getByText('Fresh'), { timeout: 100 })
+10 -16
View File
@@ -24,22 +24,7 @@ export const createQueryByError = (error: Error, callsite: Function) => {
throw new ErrorWithStack(error.message, callsite);
};
const warned = {
getByName: false,
getAllByName: false,
queryByName: false,
queryAllByName: false,
getByProps: false,
getAllByProps: false,
queryByProps: false,
queryAllByProps: false,
getByType: false,
getAllByType: false,
queryByType: false,
queryAllByType: false,
};
const warned = {};
export function printDeprecationWarning(functionName: string) {
if (warned[functionName]) {
@@ -67,3 +52,12 @@ export function printUnsafeWarning(functionName: string) {
warned[functionName] = true;
}
export function throwRemovedFunctionError(
functionName: string,
docsRef: string
) {
throw new Error(
`${functionName} has been removed in version 2.0.\n\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`
);
}
+64 -87
View File
@@ -5,16 +5,11 @@ import {
ErrorWithStack,
createLibraryNotSupportedError,
prepareErrorMessage,
printDeprecationWarning,
printUnsafeWarning,
throwRemovedFunctionError,
} from './errors';
const filterNodeByType = (node, type) => node.type === type;
const filterNodeByName = (node, name) =>
typeof node.type !== 'string' &&
(node.type.displayName === name || node.type.name === name);
const getNodeByText = (node, text) => {
try {
// eslint-disable-next-line
@@ -85,28 +80,6 @@ const getTextInputNodeByDisplayValue = (node, value) => {
}
};
export const getByName = (instance: ReactTestInstance, warnFn?: Function) =>
function getByNameFn(name: string | React.ComponentType<any>) {
warnFn && warnFn('getByName');
try {
return typeof name === 'string'
? instance.find((node) => filterNodeByName(node, name))
: instance.findByType(name);
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), getByNameFn);
}
};
export const getByType = (instance: ReactTestInstance, warnFn?: Function) =>
function getByTypeFn(type: React.ComponentType<any>) {
warnFn && warnFn('getByType');
try {
return instance.findByType(type);
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);
}
};
export const getByText = (instance: ReactTestInstance) =>
function getByTextFn(text: string | RegExp) {
try {
@@ -138,16 +111,6 @@ export const getByDisplayValue = (instance: ReactTestInstance) =>
}
};
export const getByProps = (instance: ReactTestInstance, warnFn?: Function) =>
function getByPropsFn(props: { [propName: string]: any }) {
warnFn && warnFn('getByProps');
try {
return instance.findByProps(props);
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);
}
};
export const getByTestId = (instance: ReactTestInstance) =>
function getByTestIdFn(testID: string) {
try {
@@ -167,29 +130,6 @@ export const getByTestId = (instance: ReactTestInstance) =>
}
};
export const getAllByName = (instance: ReactTestInstance, warnFn?: Function) =>
function getAllByNameFn(name: string | React.ComponentType<any>) {
warnFn && warnFn('getAllByName');
const results =
typeof name === 'string'
? instance.findAll((node) => filterNodeByName(node, name))
: instance.findAllByType(name);
if (results.length === 0) {
throw new ErrorWithStack('No instances found', getAllByNameFn);
}
return results;
};
export const getAllByType = (instance: ReactTestInstance, warnFn?: Function) =>
function getAllByTypeFn(type: React.ComponentType<any>) {
warnFn && warnFn('getAllByType');
const results = instance.findAllByType(type);
if (results.length === 0) {
throw new ErrorWithStack('No instances found', getAllByTypeFn);
}
return results;
};
export const getAllByText = (instance: ReactTestInstance) =>
function getAllByTextFn(text: string | RegExp) {
const results = instance.findAll((node) => getNodeByText(node, text));
@@ -230,19 +170,6 @@ export const getAllByDisplayValue = (instance: ReactTestInstance) =>
return results;
};
export const getAllByProps = (instance: ReactTestInstance, warnFn?: Function) =>
function getAllByPropsFn(props: { [propName: string]: any }) {
warnFn && warnFn('getAllByProps');
const results = instance.findAllByProps(props);
if (results.length === 0) {
throw new ErrorWithStack(
`No instances found with props:\n${prettyFormat(props)}`,
getAllByPropsFn
);
}
return results;
};
export const getAllByTestId = (instance: ReactTestInstance) =>
function getAllByTestIdFn(testID: string): ReactTestInstance[] {
const results = instance
@@ -258,25 +185,75 @@ export const getAllByTestId = (instance: ReactTestInstance) =>
return results;
};
export const UNSAFE_getByType = (instance: ReactTestInstance) =>
function getByTypeFn(type: React.ComponentType<any>) {
try {
return instance.findByType(type);
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), getByTypeFn);
}
};
export const UNSAFE_getByProps = (instance: ReactTestInstance) =>
function getByPropsFn(props: { [propName: string]: any }) {
try {
return instance.findByProps(props);
} catch (error) {
throw new ErrorWithStack(prepareErrorMessage(error), getByPropsFn);
}
};
export const UNSAFE_getAllByType = (instance: ReactTestInstance) =>
function getAllByTypeFn(type: React.ComponentType<any>) {
const results = instance.findAllByType(type);
if (results.length === 0) {
throw new ErrorWithStack('No instances found', getAllByTypeFn);
}
return results;
};
export const UNSAFE_getAllByProps = (instance: ReactTestInstance) =>
function getAllByPropsFn(props: { [propName: string]: any }) {
const results = instance.findAllByProps(props);
if (results.length === 0) {
throw new ErrorWithStack(
`No instances found with props:\n${prettyFormat(props)}`,
getAllByPropsFn
);
}
return results;
};
export const getByAPI = (instance: ReactTestInstance) => ({
getByTestId: getByTestId(instance),
getByName: getByName(instance, printDeprecationWarning),
getByType: getByType(instance, printUnsafeWarning),
getByText: getByText(instance),
getByPlaceholder: getByPlaceholder(instance),
getByDisplayValue: getByDisplayValue(instance),
getByProps: getByProps(instance, printUnsafeWarning),
getAllByTestId: getAllByTestId(instance),
getAllByName: getAllByName(instance, printDeprecationWarning),
getAllByType: getAllByType(instance, printUnsafeWarning),
getByTestId: getByTestId(instance),
getAllByText: getAllByText(instance),
getAllByPlaceholder: getAllByPlaceholder(instance),
getAllByDisplayValue: getAllByDisplayValue(instance),
getAllByProps: getAllByProps(instance, printUnsafeWarning),
getAllByTestId: getAllByTestId(instance),
// Unsafe aliases
UNSAFE_getByType: getByType(instance),
UNSAFE_getAllByType: getAllByType(instance),
UNSAFE_getByProps: getByProps(instance),
UNSAFE_getAllByProps: getAllByProps(instance),
// Unsafe
UNSAFE_getByType: UNSAFE_getByType(instance),
UNSAFE_getAllByType: UNSAFE_getAllByType(instance),
UNSAFE_getByProps: UNSAFE_getByProps(instance),
UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
// Removed
getByName: () =>
throwRemovedFunctionError('getByName', 'migration-v2#removed-functions'),
getAllByName: () =>
throwRemovedFunctionError('getAllByName', 'migration-v2#removed-functions'),
getByType: () =>
throwRemovedFunctionError('getByType', 'migration-v2#removed-functions'),
getAllByType: () =>
throwRemovedFunctionError('getAllByType', 'migration-v2#removed-functions'),
getByProps: () =>
throwRemovedFunctionError('getByProps', 'migration-v2#removed-functions'),
getAllByProps: () =>
throwRemovedFunctionError(
'getAllByProps',
'migration-v2#removed-functions'
),
});
+71 -88
View File
@@ -2,45 +2,19 @@
import * as React from 'react';
import {
getByTestId,
getByName,
getByType,
getByText,
getByPlaceholder,
getByDisplayValue,
getByProps,
getAllByTestId,
getAllByName,
getAllByType,
getAllByText,
getAllByPlaceholder,
getAllByDisplayValue,
getAllByProps,
UNSAFE_getByType,
UNSAFE_getByProps,
UNSAFE_getAllByType,
UNSAFE_getAllByProps,
} from './getByAPI';
import {
createQueryByError,
printDeprecationWarning,
printUnsafeWarning,
} from './errors';
export const queryByName = (instance: ReactTestInstance, warnFn?: Function) =>
function queryByNameFn(name: string | React.ComponentType<any>) {
warnFn && warnFn('queryByName');
try {
return getByName(instance)(name);
} catch (error) {
return createQueryByError(error, queryByNameFn);
}
};
export const queryByType = (instance: ReactTestInstance, warnFn?: Function) =>
function queryByTypeFn(type: React.ComponentType<any>) {
warnFn && warnFn('queryByType');
try {
return getByType(instance)(type);
} catch (error) {
return createQueryByError(error, queryByTypeFn);
}
};
import { createQueryByError, throwRemovedFunctionError } from './errors';
export const queryByText = (instance: ReactTestInstance) =>
function queryByTextFn(text: string | RegExp) {
@@ -69,16 +43,6 @@ export const queryByDisplayValue = (instance: ReactTestInstance) =>
}
};
export const queryByProps = (instance: ReactTestInstance, warnFn?: Function) =>
function queryByPropsFn(props: { [propName: string]: any }) {
warnFn && warnFn('queryByProps');
try {
return getByProps(instance)(props);
} catch (error) {
return createQueryByError(error, queryByPropsFn);
}
};
export const queryByTestId = (instance: ReactTestInstance) =>
function queryByTestIdFn(testID: string) {
try {
@@ -88,30 +52,6 @@ export const queryByTestId = (instance: ReactTestInstance) =>
}
};
export const queryAllByName = (
instance: ReactTestInstance,
warnFn?: Function
) => (name: string | React.ComponentType<any>) => {
warnFn && warnFn('queryAllByName');
try {
return getAllByName(instance)(name);
} catch (error) {
return [];
}
};
export const queryAllByType = (
instance: ReactTestInstance,
warnFn?: Function
) => (type: React.ComponentType<any>) => {
warnFn && warnFn('queryAllByType');
try {
return getAllByType(instance)(type);
} catch (error) {
return [];
}
};
export const queryAllByText = (instance: ReactTestInstance) => (
text: string | RegExp
) => {
@@ -142,18 +82,6 @@ export const queryAllByDisplayValue = (instance: ReactTestInstance) => (
}
};
export const queryAllByProps = (
instance: ReactTestInstance,
warnFn?: Function
) => (props: { [propName: string]: any }) => {
warnFn && warnFn('queryAllByProps');
try {
return getAllByProps(instance)(props);
} catch (error) {
return [];
}
};
export const queryAllByTestId = (instance: ReactTestInstance) => (
testID: string
) => {
@@ -164,25 +92,80 @@ export const queryAllByTestId = (instance: ReactTestInstance) => (
}
};
export const UNSAFE_queryByType = (instance: ReactTestInstance) =>
function queryByTypeFn(type: React.ComponentType<any>) {
try {
return UNSAFE_getByType(instance)(type);
} catch (error) {
return createQueryByError(error, queryByTypeFn);
}
};
export const UNSAFE_queryByProps = (instance: ReactTestInstance) =>
function queryByPropsFn(props: { [propName: string]: any }) {
try {
return UNSAFE_getByProps(instance)(props);
} catch (error) {
return createQueryByError(error, queryByPropsFn);
}
};
export const UNSAFE_queryAllByType = (instance: ReactTestInstance) => (
type: React.ComponentType<any>
) => {
try {
return UNSAFE_getAllByType(instance)(type);
} catch (error) {
return [];
}
};
export const UNSAFE_queryAllByProps = (instance: ReactTestInstance) => (props: {
[propName: string]: any,
}) => {
try {
return UNSAFE_getAllByProps(instance)(props);
} catch (error) {
return [];
}
};
export const queryByAPI = (instance: ReactTestInstance) => ({
queryByTestId: queryByTestId(instance),
queryByName: queryByName(instance, printDeprecationWarning),
queryByType: queryByType(instance, printUnsafeWarning),
queryByText: queryByText(instance),
queryByPlaceholder: queryByPlaceholder(instance),
queryByDisplayValue: queryByDisplayValue(instance),
queryByProps: queryByProps(instance, printUnsafeWarning),
queryAllByTestId: queryAllByTestId(instance),
queryAllByName: queryAllByName(instance, printDeprecationWarning),
queryAllByType: queryAllByType(instance, printUnsafeWarning),
queryAllByText: queryAllByText(instance),
queryAllByPlaceholder: queryAllByPlaceholder(instance),
queryAllByDisplayValue: queryAllByDisplayValue(instance),
queryAllByProps: queryAllByProps(instance, printUnsafeWarning),
// Unsafe aliases
UNSAFE_queryByType: queryByType(instance),
UNSAFE_queryAllByType: queryAllByType(instance),
UNSAFE_queryByProps: queryByProps(instance),
UNSAFE_queryAllByProps: queryAllByProps(instance),
// Unsafe
UNSAFE_queryByType: UNSAFE_queryByType(instance),
UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),
UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance),
// Removed
queryByName: () =>
throwRemovedFunctionError('queryByName', 'migration-v2#removed-functions'),
queryAllByName: () =>
throwRemovedFunctionError(
'queryAllByName',
'migration-v2#removed-functions'
),
queryByType: () =>
throwRemovedFunctionError('queryByType', 'migration-v2#removed-functions'),
queryAllByType: () =>
throwRemovedFunctionError(
'queryAllByType',
'migration-v2#removed-functions'
),
queryByProps: () =>
throwRemovedFunctionError('queryByProps', 'migration-v2#removed-functions'),
queryAllByProps: () =>
throwRemovedFunctionError(
'queryAllByProps',
'migration-v2#removed-functions'
),
});
+2 -2
View File
@@ -5,7 +5,7 @@ import fireEvent from './fireEvent';
import flushMicrotasksQueue from './flushMicrotasksQueue';
import render from './render';
import shallow from './shallow';
import waitFor from './waitFor';
import waitFor, { waitForElement } from './waitFor';
import within from './within';
export { act };
@@ -14,5 +14,5 @@ export { fireEvent };
export { flushMicrotasksQueue };
export { render };
export { shallow };
export { waitFor };
export { waitFor, waitForElement };
export { within };
+6 -7
View File
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies
import { printDeprecationWarning } from './helpers/errors';
import { throwRemovedFunctionError } from './helpers/errors';
/**
* Renders test component shallowly using react-test-renderer/shallow
@@ -18,10 +18,9 @@ export function shallowInternal(
};
}
export default function shallow(
instance: ReactTestInstance | React.Element<any>
) {
printDeprecationWarning('shallow');
return shallowInternal(instance);
export default function shallow(_: ReactTestInstance | React.Element<any>) {
throwRemovedFunctionError(
'shallow',
'migration-v2#removed-global-shallow-function'
);
}
+15
View File
@@ -1,5 +1,7 @@
// @flow
import { throwRemovedFunctionError } from './helpers/errors';
const DEFAULT_TIMEOUT = 4500;
const DEFAULT_INTERVAL = 50;
@@ -35,3 +37,16 @@ export default function waitFor<T>(
setTimeout(runExpectation, 0);
});
}
export function waitForElement<T>(
expectation: () => T,
_timeout: number = 4500,
_interval: number = 50
): Promise<T> {
throwRemovedFunctionError(
'waitForElement',
'migration-v2#waitfor-api-changes'
);
return Promise.reject();
}
+60 -58
View File
@@ -15,9 +15,9 @@ interface HasRequiredProp {
requiredProp: string;
}
const View = props => props.children;
const Text = props => props.children;
const TextInput = props => props.children;
const View = (props) => props.children;
const Text = (props) => props.children;
const TextInput = (props) => props.children;
const ElementWithRequiredProps = (props: HasRequiredProp) => (
<Text>{props.requiredProp}</Text>
);
@@ -32,10 +32,8 @@ const TestComponent = () => (
const tree = render(<TestComponent />);
// getByAPI tests
const getByNameString: ReactTestInstance = tree.getByName('View');
const getByNameContructor: ReactTestInstance = tree.getByName(View);
const getByType: ReactTestInstance = tree.getByType(View);
const getByTypeWithRequiredProps: ReactTestInstance = tree.getByType(
const getByType: ReactTestInstance = tree.UNSAFE_getByType(View);
const getByTypeWithRequiredProps: ReactTestInstance = tree.UNSAFE_getByType(
ElementWithRequiredProps
);
const getByTextString: ReactTestInstance = tree.getByText('<View />');
@@ -52,30 +50,24 @@ const getByDisplayValueString: ReactTestInstance = tree.getByDisplayValue(
const getByDisplayValueRegExp: ReactTestInstance = tree.getByDisplayValue(
/value/g
);
const getByProps: ReactTestInstance = tree.getByProps({ value: 2 });
const getByProps: ReactTestInstance = tree.UNSAFE_getByProps({ value: 2 });
const getByTestId: ReactTestInstance = tree.getByTestId('test-id');
const getAllByTestId: ReactTestInstance[] = tree.getAllByTestId('test-id');
const getAllByNameString: Array<ReactTestInstance> = tree.getAllByName('View');
const getAllByNameConstructor: Array<ReactTestInstance> = tree.getAllByName(
View
const getAllByType: Array<ReactTestInstance> = tree.UNSAFE_getAllByType(View);
const getAllByTypeWithRequiredProps: Array<ReactTestInstance> = tree.UNSAFE_getAllByType(
ElementWithRequiredProps
);
const getAllByType: Array<ReactTestInstance> = tree.getAllByType(View);
const getAllByTypeWithRequiredProps: Array<
ReactTestInstance
> = tree.getAllByType(ElementWithRequiredProps);
const getAllByTextString: Array<ReactTestInstance> = tree.getAllByText(
'<View />'
);
const getAllByTextRegExp: Array<ReactTestInstance> = tree.getAllByText(/Text/g);
const getAllByProps: Array<ReactTestInstance> = tree.getAllByProps({
const getAllByProps: Array<ReactTestInstance> = tree.UNSAFE_getAllByProps({
value: 2,
});
// queuryByAPI tests
const queryByNameString: ReactTestInstance | null = tree.queryByName('View');
const queryByNameConstructor: ReactTestInstance | null = tree.queryByName(View);
const queryByType: ReactTestInstance | null = tree.queryByType(View);
const queryByTypeWithRequiredProps: ReactTestInstance | null = tree.queryByType(
const queryByType: ReactTestInstance | null = tree.UNSAFE_queryByType(View);
const queryByTypeWithRequiredProps: ReactTestInstance | null = tree.UNSAFE_queryByType(
ElementWithRequiredProps
);
const queryByTextString: ReactTestInstance | null = tree.queryByText('View');
@@ -92,33 +84,31 @@ const queryByDisplayValueString: ReactTestInstance | null = tree.queryByDisplayV
const queryByDisplayValueRegExp: ReactTestInstance | null = tree.queryByDisplayValue(
/value/g
);
const queryByProps: ReactTestInstance | null = tree.queryByProps({ value: 2 });
const queryByProps: ReactTestInstance | null = tree.UNSAFE_queryByProps({
value: 2,
});
const queryByTestId: ReactTestInstance | null = tree.queryByTestId('test-id');
const queryAllByTestId: ReactTestInstance[] | null = tree.queryAllByTestId(
'test-id'
);
const queryAllByNameString: Array<ReactTestInstance> = tree.queryAllByName(
'View'
);
const queryAllByNameConstructor: Array<ReactTestInstance> = tree.queryAllByName(
const queryAllByType: Array<ReactTestInstance> = tree.UNSAFE_queryAllByType(
View
);
const queryAllByType: Array<ReactTestInstance> = tree.queryAllByType(View);
const queryAllByTypeWithRequiredProps: Array<
ReactTestInstance
> = tree.queryAllByType(ElementWithRequiredProps);
const queryAllByTypeWithRequiredProps: Array<ReactTestInstance> = tree.UNSAFE_queryAllByType(
ElementWithRequiredProps
);
const queryAllByTextString: Array<ReactTestInstance> = tree.queryAllByText(
'View'
);
const queryAllByTextRegExp: Array<ReactTestInstance> = tree.queryAllByText(
/View/g
);
const queryAllByDisplayValueString: Array<
ReactTestInstance
> = tree.queryAllByDisplayValue('View');
const queryAllByDisplayValueRegExp: Array<
ReactTestInstance
> = tree.queryAllByDisplayValue(/View/g);
const queryAllByDisplayValueString: Array<ReactTestInstance> = tree.queryAllByDisplayValue(
'View'
);
const queryAllByDisplayValueRegExp: Array<ReactTestInstance> = tree.queryAllByDisplayValue(
/View/g
);
// findBy API tests
const findBy: Promise<ReactTestInstance>[] = [
@@ -200,33 +190,45 @@ const queryAllByA11yRole: Array<ReactTestInstance> = tree.queryAllByA11yRole(
);
const getByA11yStates: ReactTestInstance = tree.getByA11yStates('selected');
const getByA11yStatesArray: ReactTestInstance = tree.getByA11yStates(['selected']);
const getByA11yStatesArray: ReactTestInstance = tree.getByA11yStates([
'selected',
]);
const getAllByA11yStates: Array<ReactTestInstance> = tree.getAllByA11yStates(
'selected'
);
const getAllByA11yStatesArray: Array<
ReactTestInstance
> = tree.getAllByA11yStates(['selected']);
const getAllByA11yStatesArray: Array<ReactTestInstance> = tree.getAllByA11yStates(
['selected']
);
const queryByA11yStates: ReactTestInstance = tree.queryByA11yStates('selected');
const queryByA11yStatesArray: ReactTestInstance = tree.queryByA11yStates([
'selected',
]);
const queryAllByA11yStates: Array<
ReactTestInstance
> = tree.queryAllByA11yStates('selected');
const queryAllByA11yStatesArray: Array<
ReactTestInstance
> = tree.queryAllByA11yStates(['selected']);
const queryAllByA11yStates: Array<ReactTestInstance> = tree.queryAllByA11yStates(
'selected'
);
const queryAllByA11yStatesArray: Array<ReactTestInstance> = tree.queryAllByA11yStates(
['selected']
);
const getByA11yState: ReactTestInstance = tree.getByA11yState({ busy: true });
const getAllByA11yState: Array<ReactTestInstance> = tree.getAllByA11yState({ busy: true });
const queryByA11yState: ReactTestInstance = tree.queryByA11yState({ busy: true });
const queryAllByA11yState: Array<ReactTestInstance> = tree.queryAllByA11yState({ busy: true });
const getAllByA11yState: Array<ReactTestInstance> = tree.getAllByA11yState({
busy: true,
});
const queryByA11yState: ReactTestInstance = tree.queryByA11yState({
busy: true,
});
const queryAllByA11yState: Array<ReactTestInstance> = tree.queryAllByA11yState({
busy: true,
});
const getByA11yValue: ReactTestInstance = tree.getByA11yValue({ min: 10 });
const getAllByA11yValue: Array<ReactTestInstance> = tree.getAllByA11yValue({ min: 10 });
const getAllByA11yValue: Array<ReactTestInstance> = tree.getAllByA11yValue({
min: 10,
});
const queryByA11yValue: ReactTestInstance = tree.queryByA11yValue({ min: 10 });
const queryAllByA11yValue: Array<ReactTestInstance> = tree.queryAllByA11yValue({ min: 10 });
const queryAllByA11yValue: Array<ReactTestInstance> = tree.queryAllByA11yValue({
min: 10,
});
const debugFn = tree.debug();
const debugFnWithMessage = tree.debug('my message');
@@ -236,12 +238,12 @@ tree.rerender(<View />);
tree.unmount();
// fireEvent API tests
fireEvent(getByNameString, 'press');
fireEvent(getByNameString, 'press', 'data');
fireEvent(getByNameString, 'press', 'param1', 'param2');
fireEvent.press(getByNameString);
fireEvent.changeText(getByNameString, 'string');
fireEvent.scroll(getByNameString, 'eventData');
fireEvent(getByA11yLabel, 'press');
fireEvent(getByA11yLabel, 'press', 'data');
fireEvent(getByA11yLabel, 'press', 'param1', 'param2');
fireEvent.press(getByA11yLabel);
fireEvent.changeText(getByA11yLabel, 'string');
fireEvent.scroll(getByA11yLabel, 'eventData');
// shallow API
const shallowTree: { output: React.ReactElement<any> } = shallow(
@@ -251,10 +253,10 @@ const shallowTree: { output: React.ReactElement<any> } = shallow(
const waitForFlush: Promise<any> = flushMicrotasksQueue();
const waitBy: Promise<ReactTestInstance> = waitFor<ReactTestInstance>(() =>
tree.getByName('View')
tree.getByA11yLabel('label')
);
const waitByAll: Promise<ReactTestInstance[]> = waitFor<ReactTestInstance[]>(
() => tree.getAllByName('View'),
() => tree.getAllByA11yLabel('label'),
{ timeout: 1000, interval: 50 }
);
+129 -63
View File
@@ -1,5 +1,9 @@
import * as React from 'react';
import { AccessibilityState, AccessibilityStates, AccessibilityRole } from 'react-native';
import {
AccessibilityState,
AccessibilityStates,
AccessibilityRole,
} from 'react-native';
import { ReactTestInstance, ReactTestRendererJSON } from 'react-test-renderer';
type GetReturn = ReactTestInstance;
@@ -10,48 +14,62 @@ type FindReturn = Promise<ReactTestInstance>;
type FindAllReturn = Promise<ReactTestInstance[]>;
interface GetByAPI {
getByName: (name: React.ReactType | string) => ReactTestInstance;
getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
getByText: (text: string | RegExp) => ReactTestInstance;
getByPlaceholder: (placeholder: string | RegExp) => ReactTestInstance;
getByDisplayValue: (value: string | RegExp) => ReactTestInstance;
getByProps: (props: Record<string, any>) => ReactTestInstance;
getByTestId: (testID: string) => ReactTestInstance;
getAllByTestId: (testID: string) => Array<ReactTestInstance>;
getAllByName: (name: React.ReactType | string) => Array<ReactTestInstance>;
getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
getAllByText: (text: string | RegExp) => Array<ReactTestInstance>;
getAllByPlaceholder: (
placeholder: string | RegExp
) => Array<ReactTestInstance>;
getAllByDisplayValue: (value: string | RegExp) => Array<ReactTestInstance>;
getAllByProps: (props: Record<string, any>) => Array<ReactTestInstance>;
// Unsafe aliases
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance,
UNSAFE_getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>,
UNSAFE_getByProps: (props: Record<string, any>) => ReactTestInstance,
UNSAFE_getAllByProps: (props: Record<string, any>) => Array<ReactTestInstance>,
UNSAFE_getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
UNSAFE_getAllByType: <P>(
type: React.ComponentType<P>
) => Array<ReactTestInstance>;
UNSAFE_getByProps: (props: Record<string, any>) => ReactTestInstance;
UNSAFE_getAllByProps: (
props: Record<string, any>
) => Array<ReactTestInstance>;
// Removed
/**
* @deprecated This function has been removed. Please use other queries.
*/
getByName: (name: React.ReactType | string) => ReactTestInstance;
/**
* @deprecated This function has been renamed to `UNSAFE_getByType`.
*/
getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
/**
* @deprecated This function has been renamed to `UNSAFE_getByProps`.
*/
getByProps: (props: Record<string, any>) => ReactTestInstance;
/**
* @deprecated This function has been removed. Please use other queries.
*/
getAllByName: (name: React.ReactType | string) => Array<ReactTestInstance>;
/**
* @deprecated This function has been renamed to `UNSAFE_getAllByType`.
*/
getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
/**
* @deprecated This function has been renamed to `UNSAFE_getAllByProps`.
*/
getAllByProps: (props: Record<string, any>) => Array<ReactTestInstance>;
}
interface QueryByAPI {
queryByName: (name: React.ReactType | string) => ReactTestInstance | null;
queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
queryByText: (name: string | RegExp) => ReactTestInstance | null;
queryByPlaceholder: (
placeholder: string | RegExp
) => ReactTestInstance | null;
queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null;
queryByProps: (props: Record<string, any>) => ReactTestInstance | null;
queryByTestId: (testID: string) => ReactTestInstance | null;
queryAllByTestId: (testID: string) => Array<ReactTestInstance> | null;
queryAllByName: (
name: React.ReactType | string
) => Array<ReactTestInstance> | [];
queryAllByType: <P>(
type: React.ComponentType<P>
) => Array<ReactTestInstance> | [];
queryAllByText: (text: string | RegExp) => Array<ReactTestInstance> | [];
queryAllByPlaceholder: (
placeholder: string | RegExp
@@ -59,20 +77,50 @@ interface QueryByAPI {
queryAllByDisplayValue: (
value: string | RegExp
) => Array<ReactTestInstance> | [];
queryAllByProps: (
// Unsafe aliases
UNSAFE_queryByType: <P>(
type: React.ComponentType<P>
) => ReactTestInstance | null;
UNSAFE_queryAllByType: <P>(
type: React.ComponentType<P>
) => Array<ReactTestInstance> | [];
UNSAFE_queryByProps: (props: Record<string, any>) => ReactTestInstance | null;
UNSAFE_queryAllByProps: (
props: Record<string, any>
) => Array<ReactTestInstance> | [];
// Unsafe aliases
UNSAFE_queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null,
UNSAFE_queryAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance> | [],
UNSAFE_queryByProps: (props: Record<string, any>) => ReactTestInstance | null,
UNSAFE_queryAllByProps: (props: Record<string, any>) => Array<ReactTestInstance> | [],
}
export interface WaitForOptions {
timeout: number;
interval: number;
// Removed
/**
* @deprecated This function has been removed. Please use other queries.
*/
queryByName: (name: React.ReactType | string) => ReactTestInstance | null;
/**
* @deprecated This function has been renamed to `UNSAFE_queryByType`.
*/
queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
/**
* @deprecated This function has been renamed to `UNSAFE_queryByProps`.
*/
queryByProps: (props: Record<string, any>) => ReactTestInstance | null;
/**
* @deprecated This function has been removed. Please use other queries.
*/
queryAllByName: (
name: React.ReactType | string
) => Array<ReactTestInstance> | [];
/**
* @deprecated This function has been renamed to `UNSAFE_queryAllByType`.
*/
queryAllByType: <P>(
type: React.ComponentType<P>
) => Array<ReactTestInstance> | [];
/**
* @deprecated This function has been renamed to `UNSAFE_queryAllByProps`.
*/
queryAllByProps: (
props: Record<string, any>
) => Array<ReactTestInstance> | [];
}
interface FindByAPI {
@@ -109,18 +157,18 @@ interface FindByAPI {
// Not yet available in DefinitelyTyped
export type A11yValue = {
min?: number,
max?: number,
now?: number,
text?: string,
min?: number;
max?: number;
now?: number;
text?: string;
};
type A11yAPI = {
// Label
getByA11yLabel: (matcher: string | RegExp) => GetReturn,
getAllByA11yLabel: (matcher: string | RegExp) => GetAllReturn,
queryByA11yLabel: (matcher: string | RegExp) => QueryReturn,
queryAllByA11yLabel: (matcher: string | RegExp) => QueryAllReturn,
getByA11yLabel: (matcher: string | RegExp) => GetReturn;
getAllByA11yLabel: (matcher: string | RegExp) => GetAllReturn;
queryByA11yLabel: (matcher: string | RegExp) => QueryReturn;
queryAllByA11yLabel: (matcher: string | RegExp) => QueryAllReturn;
findByA11yLabel: (
matcher: string | RegExp,
waitForOptions?: WaitForOptions
@@ -131,10 +179,10 @@ type A11yAPI = {
) => FindAllReturn;
// Hint
getByA11yHint: (matcher: string | RegExp) => GetReturn,
getAllByA11yHint: (matcher: string | RegExp) => GetAllReturn,
queryByA11yHint: (matcher: string | RegExp) => QueryReturn,
queryAllByA11yHint: (matcher: string | RegExp) => QueryAllReturn,
getByA11yHint: (matcher: string | RegExp) => GetReturn;
getAllByA11yHint: (matcher: string | RegExp) => GetAllReturn;
queryByA11yHint: (matcher: string | RegExp) => QueryReturn;
queryAllByA11yHint: (matcher: string | RegExp) => QueryAllReturn;
findByA11yHint: (
matcher: string | RegExp,
waitForOptions?: WaitForOptions
@@ -145,10 +193,10 @@ type A11yAPI = {
) => FindAllReturn;
// Role
getByA11yRole: (matcher: AccessibilityRole | RegExp) => GetReturn,
getAllByA11yRole: (matcher: AccessibilityRole | RegExp) => GetAllReturn,
queryByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryReturn,
queryAllByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryAllReturn,
getByA11yRole: (matcher: AccessibilityRole | RegExp) => GetReturn;
getAllByA11yRole: (matcher: AccessibilityRole | RegExp) => GetAllReturn;
queryByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryReturn;
queryAllByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryAllReturn;
findByA11yRole: (
matcher: AccessibilityRole | RegExp,
waitForOptions?: WaitForOptions
@@ -159,16 +207,24 @@ type A11yAPI = {
) => FindAllReturn;
// States
getByA11yStates: (matcher: AccessibilityStates | Array<AccessibilityStates>) => GetReturn,
getAllByA11yStates: (matcher: AccessibilityStates | Array<AccessibilityStates>) => GetAllReturn,
queryByA11yStates: (matcher: AccessibilityStates | Array<AccessibilityStates>) => QueryReturn,
queryAllByA11yStates: (matcher: AccessibilityStates | Array<AccessibilityStates>) => QueryAllReturn,
getByA11yStates: (
matcher: AccessibilityStates | Array<AccessibilityStates>
) => GetReturn;
getAllByA11yStates: (
matcher: AccessibilityStates | Array<AccessibilityStates>
) => GetAllReturn;
queryByA11yStates: (
matcher: AccessibilityStates | Array<AccessibilityStates>
) => QueryReturn;
queryAllByA11yStates: (
matcher: AccessibilityStates | Array<AccessibilityStates>
) => QueryAllReturn;
// State
getByA11yState: (matcher: AccessibilityState) => GetReturn,
getAllByA11yState: (matcher: AccessibilityState) => GetAllReturn,
queryByA11yState: (matcher: AccessibilityState) => QueryReturn,
queryAllByA11yState: (matcher: AccessibilityState) => QueryAllReturn,
getByA11yState: (matcher: AccessibilityState) => GetReturn;
getAllByA11yState: (matcher: AccessibilityState) => GetAllReturn;
queryByA11yState: (matcher: AccessibilityState) => QueryReturn;
queryAllByA11yState: (matcher: AccessibilityState) => QueryAllReturn;
findByA11yState: (
matcher: AccessibilityState,
waitForOptions?: WaitForOptions
@@ -179,10 +235,10 @@ type A11yAPI = {
) => FindAllReturn;
// Value
getByA11yValue: (matcher: A11yValue) => GetReturn,
getAllByA11yValue: (matcher: A11yValue) => GetAllReturn,
queryByA11yValue: (matcher: A11yValue) => QueryReturn,
queryAllByA11yValue: (matcher: A11yValue) => QueryAllReturn,
getByA11yValue: (matcher: A11yValue) => GetReturn;
getAllByA11yValue: (matcher: A11yValue) => GetAllReturn;
queryByA11yValue: (matcher: A11yValue) => QueryReturn;
queryAllByA11yValue: (matcher: A11yValue) => QueryAllReturn;
findByA11yValue: (
matcher: A11yValue,
waitForOptions?: WaitForOptions
@@ -238,12 +294,22 @@ export declare const render: (
component: React.ReactElement<any>,
options?: RenderOptions
) => RenderAPI;
export declare const shallow: <P = {}>(
instance: ReactTestInstance | React.ReactElement<P>
) => { output: React.ReactElement<P> };
export declare const flushMicrotasksQueue: () => Promise<any>;
export declare const cleanup: () => void;
export declare const fireEvent: FireEventAPI;
export declare const waitFor: WaitForFunction;
export declare const act: (callback: () => void) => Thenable;
export declare const within: (instance: ReactTestInstance) => Queries;
/**
* @deprecated This function has been removed. Please use `waitFor` function.
*/
export declare const waitForElement: WaitForFunction;
/**
* @deprecated This function has been removed.
*/
export declare const shallow: <P = {}>(
instance: ReactTestInstance | React.ReactElement<P>
) => { output: React.ReactElement<P> };
+39 -2
View File
@@ -1,5 +1,5 @@
---
id: migration20
id: migration-v2
title: Migration to 2.0
---
@@ -41,7 +41,44 @@ Please note that in many cases `waitFor` call can be replaced by proper use of `
## Removed global `debug` function
Global debug function has been removed in favor of `debug()` method returned from `render()` function.
Global `debug()` function has been removed in favor of `debug()` method returned from `render()` function.
## Removed global `shallow` function
Global `shallow()` functions which has been previously deprecated has been removed.
Shallow rendering React component is usually not a good idea, so we decided to remove the API. However, if you find it useful or need to support legacy tests, feel free to implement it yourself. Here's a sample implementation:
```js
import ShallowRenderer from 'react-test-renderer/shallow';
export function shallow(instance: ReactTestInstance | React.Element<any>) {
const renderer = new ShallowRenderer();
renderer.render(React.createElement(instance.type, instance.props));
return { output: renderer.getRenderOutput() };
}
```
## Removed functions
Following query functions have been removed after being deprecated for more than a year now:
- `getByName`
- `getAllByName`
- `queryByName`
- `queryAllByName`
The `*ByType` and `*ByProps` queries has been prefixed with `UNSAFE_`. You can safely rename them using global search/replace in your project:
- `getByType` -> `UNSAFE_getByType`
- `getAllByType` -> `UNSAFE_getAllByType`
- `queryByType` -> `UNSAFE_queryByType`
- `queryAllByType` -> `UNSAFE_queryAllByType`
- `getByProps` -> `UNSAFE_getByProps`
- `getAllByProps` -> `UNSAFE_getAllByProps`
- `queryByProps` -> `UNSAFE_queryByProps`
- `queryAllByProps` -> `UNSAFE_queryAllByProps`
## Some `byTestId` queries behavior changes
+1 -1
View File
@@ -2,7 +2,7 @@ module.exports = {
docs: {
Introduction: ['getting-started'],
'API Reference': ['api', 'api-queries'],
Guides: ['migration20'],
Guides: ['migration-v2'],
Examples: ['react-navigation', 'redux-integration'],
},
};