diff --git a/examples/redux/components/AddTodo.test.js b/examples/redux/components/AddTodo.test.js
index edbbcc163..faeca8508 100644
--- a/examples/redux/components/AddTodo.test.js
+++ b/examples/redux/components/AddTodo.test.js
@@ -14,9 +14,9 @@ describe('Application test', () => {
);
- const { getByPlaceholder, getByText } = render(component);
+ const { getByPlaceholderText, getByText } = render(component);
- const input = getByPlaceholder(/repository/i);
+ const input = getByPlaceholderText(/repository/i);
expect(input).toBeTruthy();
const textToEnter = 'This is a random element';
diff --git a/src/__tests__/findByApi.test.js b/src/__tests__/findByApi.test.js
index 191003010..f924cb1b3 100644
--- a/src/__tests__/findByApi.test.js
+++ b/src/__tests__/findByApi.test.js
@@ -11,8 +11,8 @@ test('findBy queries work asynchronously', async () => {
findAllByTestId,
findByText,
findAllByText,
- findByPlaceholder,
- findAllByPlaceholder,
+ findByPlaceholderText,
+ findAllByPlaceholderText,
findByDisplayValue,
findAllByDisplayValue,
} = render();
@@ -21,10 +21,10 @@ test('findBy queries work asynchronously', async () => {
await expect(findByText('Some Text', options)).rejects.toBeTruthy();
await expect(findAllByText('Some Text', options)).rejects.toBeTruthy();
await expect(
- findByPlaceholder('Placeholder Text', options)
+ findByPlaceholderText('Placeholder Text', options)
).rejects.toBeTruthy();
await expect(
- findAllByPlaceholder('Placeholder Text', options)
+ findAllByPlaceholderText('Placeholder Text', options)
).rejects.toBeTruthy();
await expect(
findByDisplayValue('Display Value', options)
@@ -49,10 +49,10 @@ test('findBy queries work asynchronously', async () => {
await expect(findAllByTestId('aTestId')).resolves.toHaveLength(1);
await expect(findByText('Some Text')).resolves.toBeTruthy();
await expect(findAllByText('Some Text')).resolves.toHaveLength(1);
- await expect(findByPlaceholder('Placeholder Text')).resolves.toBeTruthy();
- await expect(findAllByPlaceholder('Placeholder Text')).resolves.toHaveLength(
- 1
- );
+ await expect(findByPlaceholderText('Placeholder Text')).resolves.toBeTruthy();
+ await expect(
+ findAllByPlaceholderText('Placeholder Text')
+ ).resolves.toHaveLength(1);
await expect(findByDisplayValue('Display Value')).resolves.toBeTruthy();
await expect(findAllByDisplayValue('Display Value')).resolves.toHaveLength(1);
}, 20000);
diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js
index c1c69ebad..5a261dba7 100644
--- a/src/__tests__/fireEvent.test.js
+++ b/src/__tests__/fireEvent.test.js
@@ -123,7 +123,7 @@ test('fireEvent.changeText', () => {
const onChangeTextMock = jest.fn();
const CHANGE_TEXT = 'content';
- const { getByPlaceholder } = render(
+ const { getByPlaceholderText } = render(
{
);
- fireEvent.changeText(getByPlaceholder('Customer placeholder'), CHANGE_TEXT);
+ fireEvent.changeText(
+ getByPlaceholderText('Customer placeholder'),
+ CHANGE_TEXT
+ );
expect(onChangeTextMock).toHaveBeenCalledWith(CHANGE_TEXT);
});
diff --git a/src/__tests__/render.test.js b/src/__tests__/render.test.js
index 617cd105b..d7d4a0b2e 100644
--- a/src/__tests__/render.test.js
+++ b/src/__tests__/render.test.js
@@ -176,35 +176,39 @@ test('getAllByText, queryAllByText', () => {
expect(queryAllByText('InExistent')).toHaveLength(0);
});
-test('getByPlaceholder, queryByPlaceholder', () => {
- const { getByPlaceholder, queryByPlaceholder } = render();
- const input = getByPlaceholder(/custom/i);
+test('getByPlaceholderText, queryByPlaceholderText', () => {
+ const { getByPlaceholderText, queryByPlaceholderText } = render();
+ const input = getByPlaceholderText(/custom/i);
expect(input.props.placeholder).toBe(PLACEHOLDER_FRESHNESS);
- const sameInput = getByPlaceholder(PLACEHOLDER_FRESHNESS);
+ const sameInput = getByPlaceholderText(PLACEHOLDER_FRESHNESS);
expect(sameInput.props.placeholder).toBe(PLACEHOLDER_FRESHNESS);
- expect(() => getByPlaceholder('no placeholder')).toThrow(
+ expect(() => getByPlaceholderText('no placeholder')).toThrow(
'No instances found'
);
- expect(queryByPlaceholder(/add/i)).toBe(input);
- expect(queryByPlaceholder('no placeholder')).toBeNull();
- expect(() => queryByPlaceholder(/fresh/)).toThrow('Expected 1 but found 2');
+ expect(queryByPlaceholderText(/add/i)).toBe(input);
+ expect(queryByPlaceholderText('no placeholder')).toBeNull();
+ expect(() => queryByPlaceholderText(/fresh/)).toThrow(
+ 'Expected 1 but found 2'
+ );
});
-test('getAllByPlaceholder, queryAllByPlaceholder', () => {
- const { getAllByPlaceholder, queryAllByPlaceholder } = render();
- const inputs = getAllByPlaceholder(/fresh/i);
+test('getAllByPlaceholderText, queryAllByPlaceholderText', () => {
+ const { getAllByPlaceholderText, queryAllByPlaceholderText } = render(
+
+ );
+ const inputs = getAllByPlaceholderText(/fresh/i);
expect(inputs).toHaveLength(2);
- expect(() => getAllByPlaceholder('no placeholder')).toThrow(
+ expect(() => getAllByPlaceholderText('no placeholder')).toThrow(
'No instances found'
);
- expect(queryAllByPlaceholder(/fresh/i)).toEqual(inputs);
- expect(queryAllByPlaceholder('no placeholder')).toHaveLength(0);
+ expect(queryAllByPlaceholderText(/fresh/i)).toEqual(inputs);
+ expect(queryAllByPlaceholderText('no placeholder')).toHaveLength(0);
});
test('getByDisplayValue, queryByDisplayValue', () => {
diff --git a/src/__tests__/within.test.js b/src/__tests__/within.test.js
index a4fb956c1..51403731e 100644
--- a/src/__tests__/within.test.js
+++ b/src/__tests__/within.test.js
@@ -19,7 +19,9 @@ test('within() exposes basic queries', async () => {
expect(rootQueries.getAllByText('Same Text')).toHaveLength(2);
expect(rootQueries.getAllByDisplayValue('Same Value')).toHaveLength(2);
- expect(rootQueries.getAllByPlaceholder('Same Placeholder')).toHaveLength(2);
+ expect(rootQueries.getAllByPlaceholderText('Same Placeholder')).toHaveLength(
+ 2
+ );
const firstQueries = within(rootQueries.getByA11yHint('first'));
expect(firstQueries.getAllByText('Same Text')).toHaveLength(1);
@@ -27,12 +29,12 @@ test('within() exposes basic queries', async () => {
expect(firstQueries.queryAllByText('Same Text')).toHaveLength(1);
expect(firstQueries.queryByText('Same Text')).toBeTruthy();
expect(firstQueries.getByDisplayValue('Same Value')).toBeTruthy();
- expect(firstQueries.getByPlaceholder('Same Placeholder')).toBeTruthy();
+ expect(firstQueries.getByPlaceholderText('Same Placeholder')).toBeTruthy();
await expect(
firstQueries.findByDisplayValue('Same Value')
).resolves.toBeTruthy();
await expect(
- firstQueries.findAllByPlaceholder('Same Placeholder')
+ firstQueries.findAllByPlaceholderText('Same Placeholder')
).resolves.toHaveLength(1);
const secondQueries = within(rootQueries.getByA11yHint('second'));
@@ -41,7 +43,7 @@ test('within() exposes basic queries', async () => {
expect(secondQueries.queryAllByText('Same Text')).toHaveLength(1);
expect(secondQueries.queryByText('Same Text')).toBeTruthy();
expect(secondQueries.getByDisplayValue('Same Value')).toBeTruthy();
- expect(secondQueries.getByPlaceholder('Same Placeholder')).toBeTruthy();
+ expect(secondQueries.getByPlaceholderText('Same Placeholder')).toBeTruthy();
});
test('within() exposes a11y queries', async () => {
diff --git a/src/helpers/errors.js b/src/helpers/errors.js
index ce089b873..df76871cf 100644
--- a/src/helpers/errors.js
+++ b/src/helpers/errors.js
@@ -44,6 +44,16 @@ export function throwRemovedFunctionError(
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}`
+ `"${functionName}" has been removed.\n\nPlease consult: https://callstack.github.io/react-native-testing-library/docs/${docsRef}`
+ );
+}
+
+export function throwRenamedFunctionError(
+ functionName: string,
+ newFunctionName: string
+) {
+ throw new ErrorWithStack(
+ `The "${functionName}" function has been renamed to "${newFunctionName}". Please replace all occurrences.`,
+ throwRenamedFunctionError
);
}
diff --git a/src/helpers/findByAPI.js b/src/helpers/findByAPI.js
index 058f51fda..6234a1182 100644
--- a/src/helpers/findByAPI.js
+++ b/src/helpers/findByAPI.js
@@ -6,11 +6,12 @@ import {
getAllByTestId,
getByText,
getAllByText,
- getByPlaceholder,
- getAllByPlaceholder,
+ getByPlaceholderText,
+ getAllByPlaceholderText,
getByDisplayValue,
getAllByDisplayValue,
} from './getByAPI';
+import { throwRenamedFunctionError } from './errors';
const makeFindQuery = (
instance: ReactTestInstance,
@@ -39,15 +40,16 @@ export const findAllByText = (instance: ReactTestInstance) => (
waitForOptions: WaitForOptions = {}
) => makeFindQuery(instance, getAllByText, text, waitForOptions);
-export const findByPlaceholder = (instance: ReactTestInstance) => (
+export const findByPlaceholderText = (instance: ReactTestInstance) => (
placeholder: string | RegExp,
waitForOptions: WaitForOptions = {}
-) => makeFindQuery(instance, getByPlaceholder, placeholder, waitForOptions);
+) => makeFindQuery(instance, getByPlaceholderText, placeholder, waitForOptions);
-export const findAllByPlaceholder = (instance: ReactTestInstance) => (
+export const findAllByPlaceholderText = (instance: ReactTestInstance) => (
placeholder: string | RegExp,
waitForOptions: WaitForOptions = {}
-) => makeFindQuery(instance, getAllByPlaceholder, placeholder, waitForOptions);
+) =>
+ makeFindQuery(instance, getAllByPlaceholderText, placeholder, waitForOptions);
export const findByDisplayValue = (instance: ReactTestInstance) => (
value: string | RegExp,
@@ -62,10 +64,19 @@ export const findAllByDisplayValue = (instance: ReactTestInstance) => (
export const findByAPI = (instance: ReactTestInstance) => ({
findByTestId: findByTestId(instance),
findByText: findByText(instance),
- findByPlaceholder: findByPlaceholder(instance),
+ findByPlaceholderText: findByPlaceholderText(instance),
findByDisplayValue: findByDisplayValue(instance),
findAllByTestId: findAllByTestId(instance),
findAllByText: findAllByText(instance),
- findAllByPlaceholder: findAllByPlaceholder(instance),
+ findAllByPlaceholderText: findAllByPlaceholderText(instance),
findAllByDisplayValue: findAllByDisplayValue(instance),
+
+ // Renamed
+ findByPlaceholder: () =>
+ throwRenamedFunctionError('findByPlaceholder', 'findByPlaceholderText'),
+ findAllByPlaceholder: () =>
+ throwRenamedFunctionError(
+ 'findAllByPlaceholder',
+ 'findAllByPlaceholderText'
+ ),
});
diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js
index ea2342655..723cc20e5 100644
--- a/src/helpers/getByAPI.js
+++ b/src/helpers/getByAPI.js
@@ -6,6 +6,7 @@ import {
createLibraryNotSupportedError,
prepareErrorMessage,
throwRemovedFunctionError,
+ throwRenamedFunctionError,
} from './errors';
const filterNodeByType = (node, type) => node.type === type;
@@ -50,7 +51,7 @@ const getChildrenAsText = (children, TextComponent, textContent = []) => {
return textContent;
};
-const getTextInputNodeByPlaceholder = (node, placeholder) => {
+const getTextInputNodeByPlaceholderText = (node, placeholder) => {
try {
// eslint-disable-next-line
const { TextInput } = require('react-native');
@@ -89,14 +90,17 @@ export const getByText = (instance: ReactTestInstance) =>
}
};
-export const getByPlaceholder = (instance: ReactTestInstance) =>
- function getByPlaceholderFn(placeholder: string | RegExp) {
+export const getByPlaceholderText = (instance: ReactTestInstance) =>
+ function getByPlaceholderTextFn(placeholder: string | RegExp) {
try {
return instance.find((node) =>
- getTextInputNodeByPlaceholder(node, placeholder)
+ getTextInputNodeByPlaceholderText(node, placeholder)
);
} catch (error) {
- throw new ErrorWithStack(prepareErrorMessage(error), getByPlaceholderFn);
+ throw new ErrorWithStack(
+ prepareErrorMessage(error),
+ getByPlaceholderTextFn
+ );
}
};
@@ -142,15 +146,15 @@ export const getAllByText = (instance: ReactTestInstance) =>
return results;
};
-export const getAllByPlaceholder = (instance: ReactTestInstance) =>
- function getAllByPlaceholderFn(placeholder: string | RegExp) {
+export const getAllByPlaceholderText = (instance: ReactTestInstance) =>
+ function getAllByPlaceholderTextFn(placeholder: string | RegExp) {
const results = instance.findAll((node) =>
- getTextInputNodeByPlaceholder(node, placeholder)
+ getTextInputNodeByPlaceholderText(node, placeholder)
);
if (results.length === 0) {
throw new ErrorWithStack(
`No instances found with placeholder: ${String(placeholder)}`,
- getAllByPlaceholderFn
+ getAllByPlaceholderTextFn
);
}
return results;
@@ -226,11 +230,11 @@ export const UNSAFE_getAllByProps = (instance: ReactTestInstance) =>
export const getByAPI = (instance: ReactTestInstance) => ({
getByText: getByText(instance),
- getByPlaceholder: getByPlaceholder(instance),
+ getByPlaceholderText: getByPlaceholderText(instance),
getByDisplayValue: getByDisplayValue(instance),
getByTestId: getByTestId(instance),
getAllByText: getAllByText(instance),
- getAllByPlaceholder: getAllByPlaceholder(instance),
+ getAllByPlaceholderText: getAllByPlaceholderText(instance),
getAllByDisplayValue: getAllByDisplayValue(instance),
getAllByTestId: getAllByTestId(instance),
@@ -256,4 +260,10 @@ export const getByAPI = (instance: ReactTestInstance) => ({
'getAllByProps',
'migration-v2#removed-functions'
),
+
+ // Renamed
+ getByPlaceholder: () =>
+ throwRenamedFunctionError('getByPlaceholder', 'getByPlaceholderText'),
+ getAllByPlaceholder: () =>
+ throwRenamedFunctionError('getAllByPlaceholder', 'getByPlaceholderText'),
});
diff --git a/src/helpers/queryByAPI.js b/src/helpers/queryByAPI.js
index 5566e3e4d..fe1076e28 100644
--- a/src/helpers/queryByAPI.js
+++ b/src/helpers/queryByAPI.js
@@ -3,18 +3,22 @@ import * as React from 'react';
import {
getByTestId,
getByText,
- getByPlaceholder,
+ getByPlaceholderText,
getByDisplayValue,
getAllByTestId,
getAllByText,
- getAllByPlaceholder,
+ getAllByPlaceholderText,
getAllByDisplayValue,
UNSAFE_getByType,
UNSAFE_getByProps,
UNSAFE_getAllByType,
UNSAFE_getAllByProps,
} from './getByAPI';
-import { createQueryByError, throwRemovedFunctionError } from './errors';
+import {
+ createQueryByError,
+ throwRemovedFunctionError,
+ throwRenamedFunctionError,
+} from './errors';
export const queryByText = (instance: ReactTestInstance) =>
function queryByTextFn(text: string | RegExp) {
@@ -25,12 +29,12 @@ export const queryByText = (instance: ReactTestInstance) =>
}
};
-export const queryByPlaceholder = (instance: ReactTestInstance) =>
- function queryByPlaceholderFn(placeholder: string | RegExp) {
+export const queryByPlaceholderText = (instance: ReactTestInstance) =>
+ function queryByPlaceholderTextFn(placeholder: string | RegExp) {
try {
- return getByPlaceholder(instance)(placeholder);
+ return getByPlaceholderText(instance)(placeholder);
} catch (error) {
- return createQueryByError(error, queryByPlaceholderFn);
+ return createQueryByError(error, queryByPlaceholderTextFn);
}
};
@@ -62,11 +66,11 @@ export const queryAllByText = (instance: ReactTestInstance) => (
}
};
-export const queryAllByPlaceholder = (instance: ReactTestInstance) => (
+export const queryAllByPlaceholderText = (instance: ReactTestInstance) => (
placeholder: string | RegExp
) => {
try {
- return getAllByPlaceholder(instance)(placeholder);
+ return getAllByPlaceholderText(instance)(placeholder);
} catch (error) {
return [];
}
@@ -133,11 +137,11 @@ export const UNSAFE_queryAllByProps = (instance: ReactTestInstance) => (props: {
export const queryByAPI = (instance: ReactTestInstance) => ({
queryByTestId: queryByTestId(instance),
queryByText: queryByText(instance),
- queryByPlaceholder: queryByPlaceholder(instance),
+ queryByPlaceholderText: queryByPlaceholderText(instance),
queryByDisplayValue: queryByDisplayValue(instance),
queryAllByTestId: queryAllByTestId(instance),
queryAllByText: queryAllByText(instance),
- queryAllByPlaceholder: queryAllByPlaceholder(instance),
+ queryAllByPlaceholderText: queryAllByPlaceholderText(instance),
queryAllByDisplayValue: queryAllByDisplayValue(instance),
// Unsafe
@@ -168,4 +172,13 @@ export const queryByAPI = (instance: ReactTestInstance) => ({
'queryAllByProps',
'migration-v2#removed-functions'
),
+
+ // Renamed
+ queryByPlaceholder: () =>
+ throwRenamedFunctionError('queryByPlaceholder', 'queryByPlaceholderText'),
+ queryAllByPlaceholder: () =>
+ throwRenamedFunctionError(
+ 'queryAllByPlaceholder',
+ 'queryAllByPlaceholderText'
+ ),
});
diff --git a/typings/__tests__/index.test.tsx b/typings/__tests__/index.test.tsx
index fb45261f7..64a038e51 100644
--- a/typings/__tests__/index.test.tsx
+++ b/typings/__tests__/index.test.tsx
@@ -35,8 +35,8 @@ const tree = render();
const getBy: ReactTestInstance[] = [
tree.getByText(''),
tree.getByText(/View/g),
- tree.getByPlaceholder('my placeholder'),
- tree.getByPlaceholder(/placeholder/g),
+ tree.getByPlaceholderText('my placeholder'),
+ tree.getByPlaceholderText(/placeholder/g),
tree.getByDisplayValue('my value'),
tree.getByDisplayValue(/value/g),
tree.getByTestId('test-id'),
@@ -58,8 +58,8 @@ const getBy: ReactTestInstance[] = [
const getAllBy: ReactTestInstance[][] = [
tree.getAllByText(''),
tree.getAllByText(/Text/g),
- tree.getAllByPlaceholder('my placeholder'),
- tree.getAllByPlaceholder(/placeholder/g),
+ tree.getAllByPlaceholderText('my placeholder'),
+ tree.getAllByPlaceholderText(/placeholder/g),
tree.getAllByDisplayValue('my value'),
tree.getAllByDisplayValue(/value/g),
tree.getAllByTestId('test-id'),
@@ -82,8 +82,8 @@ const getAllBy: ReactTestInstance[][] = [
const queryBy: Array = [
tree.queryByText('View'),
tree.queryByText(/View/g),
- tree.queryByPlaceholder('my placeholder'),
- tree.queryByPlaceholder(/placeholder/g),
+ tree.queryByPlaceholderText('my placeholder'),
+ tree.queryByPlaceholderText(/placeholder/g),
tree.queryByDisplayValue('my value'),
tree.queryByDisplayValue(/value/g),
tree.queryByTestId('test-id'),
@@ -105,8 +105,8 @@ const queryBy: Array = [
const queryAllBy: ReactTestInstance[][] = [
tree.queryAllByText('View'),
tree.queryAllByText(/View/g),
- tree.queryAllByPlaceholder('my placeholder'),
- tree.queryAllByPlaceholder(/placeholder/g),
+ tree.queryAllByPlaceholderText('my placeholder'),
+ tree.queryAllByPlaceholderText(/placeholder/g),
tree.queryAllByDisplayValue('my value'),
tree.queryAllByDisplayValue(/value/g),
tree.queryAllByTestId('test-id'),
@@ -131,10 +131,10 @@ const findBy: Promise[] = [
tree.findByText('View', { timeout: 10, interval: 10 }),
tree.findByText(/View/g),
tree.findByText(/View/g, { timeout: 10, interval: 5 }),
- tree.findByPlaceholder('my placeholder'),
- tree.findByPlaceholder('my placeholder', { timeout: 10, interval: 5 }),
- tree.findByPlaceholder(/placeholder/g),
- tree.findByPlaceholder(/placeholder/g, { timeout: 10, interval: 5 }),
+ tree.findByPlaceholderText('my placeholder'),
+ tree.findByPlaceholderText('my placeholder', { timeout: 10, interval: 5 }),
+ tree.findByPlaceholderText(/placeholder/g),
+ tree.findByPlaceholderText(/placeholder/g, { timeout: 10, interval: 5 }),
tree.findByDisplayValue('my value'),
tree.findByDisplayValue('my value', { timeout: 10, interval: 10 }),
tree.findByDisplayValue(/value/g),
@@ -164,10 +164,13 @@ const findAllBy: Promise[] = [
tree.findAllByText('View', { timeout: 10, interval: 10 }),
tree.findAllByText(/View/g),
tree.findAllByText(/View/g, { timeout: 10, interval: 5 }),
- tree.findAllByPlaceholder('my placeholder'),
- tree.findAllByPlaceholder('my placeholder', { timeout: 10, interval: 10 }),
- tree.findAllByPlaceholder(/placeholder/g),
- tree.findAllByPlaceholder(/placeholder/g, { timeout: 10, interval: 10 }),
+ tree.findAllByPlaceholderText('my placeholder'),
+ tree.findAllByPlaceholderText('my placeholder', {
+ timeout: 10,
+ interval: 10,
+ }),
+ tree.findAllByPlaceholderText(/placeholder/g),
+ tree.findAllByPlaceholderText(/placeholder/g, { timeout: 10, interval: 10 }),
tree.findAllByDisplayValue('View'),
tree.findAllByDisplayValue('View', { timeout: 10, interval: 10 }),
tree.findAllByDisplayValue(/View/g),
@@ -293,7 +296,7 @@ const instance: ReactTestInstance = tree.getByText('');
const withinGet: Array = [
within(instance).getByText('Test'),
within(instance).getByDisplayValue('Test'),
- within(instance).getByPlaceholder('Test'),
+ within(instance).getByPlaceholderText('Test'),
within(instance).getByTestId('Test'),
within(instance).getByA11yLabel('Test'),
within(instance).getByLabelText('Test'),
@@ -308,7 +311,7 @@ const withinGet: Array = [
const withinGetAll: Array = [
within(instance).getAllByText('Test'),
within(instance).getAllByDisplayValue('Test'),
- within(instance).getAllByPlaceholder('Test'),
+ within(instance).getAllByPlaceholderText('Test'),
within(instance).getAllByTestId('Test'),
within(instance).getAllByA11yLabel('Test'),
within(instance).getAllByLabelText('button'),
@@ -323,7 +326,7 @@ const withinGetAll: Array = [
const withinQuery: Array = [
within(instance).queryByText('Test'),
within(instance).queryByDisplayValue('Test'),
- within(instance).queryByPlaceholder('Test'),
+ within(instance).queryByPlaceholderText('Test'),
within(instance).queryByTestId('Test'),
within(instance).queryByA11yLabel('Test'),
within(instance).queryByLabelText('button'),
@@ -338,7 +341,7 @@ const withinQuery: Array = [
const withinQueryAll: Array = [
within(instance).queryAllByText('Test'),
within(instance).queryAllByDisplayValue('Test'),
- within(instance).queryAllByPlaceholder('Test'),
+ within(instance).queryAllByPlaceholderText('Test'),
within(instance).queryAllByTestId('Test'),
within(instance).queryAllByA11yLabel('Test'),
within(instance).queryAllByLabelText('Test'),
@@ -353,7 +356,7 @@ const withinQueryAll: Array = [
const withinFind: Promise[] = [
within(instance).findByText('Test'),
within(instance).findByDisplayValue('Test'),
- within(instance).findByPlaceholder('Test'),
+ within(instance).findByPlaceholderText('Test'),
within(instance).findByTestId('Test'),
within(instance).findByA11yLabel('Test'),
within(instance).findByLabelText('Test'),
@@ -368,7 +371,7 @@ const withinFind: Promise[] = [
const withinFindAll: Promise[] = [
within(instance).findAllByText('Test'),
within(instance).findAllByDisplayValue('Test'),
- within(instance).findAllByPlaceholder('Test'),
+ within(instance).findAllByPlaceholderText('Test'),
within(instance).findAllByTestId('Test'),
within(instance).findAllByA11yLabel('Test'),
within(instance).findAllByLabelText('Test'),
diff --git a/typings/index.d.ts b/typings/index.d.ts
index da01039a7..640055fd9 100644
--- a/typings/index.d.ts
+++ b/typings/index.d.ts
@@ -16,12 +16,12 @@ type FindAllReturn = Promise;
interface GetByAPI {
getByText: (text: string | RegExp) => ReactTestInstance;
- getByPlaceholder: (placeholder: string | RegExp) => ReactTestInstance;
+ getByPlaceholderText: (placeholder: string | RegExp) => ReactTestInstance;
getByDisplayValue: (value: string | RegExp) => ReactTestInstance;
getByTestId: (testID: string) => ReactTestInstance;
getAllByTestId: (testID: string) => Array;
getAllByText: (text: string | RegExp) => Array;
- getAllByPlaceholder: (
+ getAllByPlaceholderText: (
placeholder: string | RegExp
) => Array;
getAllByDisplayValue: (value: string | RegExp) => Array;
@@ -65,14 +65,14 @@ interface GetByAPI {
interface QueryByAPI {
queryByText: (name: string | RegExp) => ReactTestInstance | null;
- queryByPlaceholder: (
+ queryByPlaceholderText: (
placeholder: string | RegExp
) => ReactTestInstance | null;
queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null;
queryByTestId: (testID: string) => ReactTestInstance | null;
queryAllByTestId: (testID: string) => Array | null;
queryAllByText: (text: string | RegExp) => Array | [];
- queryAllByPlaceholder: (
+ queryAllByPlaceholderText: (
placeholder: string | RegExp
) => Array | [];
queryAllByDisplayValue: (
@@ -129,7 +129,7 @@ interface FindByAPI {
text: string | RegExp,
waitForOptions?: WaitForOptions
) => FindReturn;
- findByPlaceholder: (
+ findByPlaceholderText: (
placeholder: string | RegExp,
waitForOptions?: WaitForOptions
) => FindReturn;
@@ -142,7 +142,7 @@ interface FindByAPI {
text: string | RegExp,
waitForOptions?: WaitForOptions
) => FindAllReturn;
- findAllByPlaceholder: (
+ findAllByPlaceholderText: (
placeholder: string | RegExp,
waitForOptions?: WaitForOptions
) => FindAllReturn;
diff --git a/website/docs/API.md b/website/docs/API.md
index d9b52069a..728cbfd63 100644
--- a/website/docs/API.md
+++ b/website/docs/API.md
@@ -177,13 +177,13 @@ import { render, fireEvent } from 'react-native-testing-library';
test('fire changeText event', () => {
const onEventMock = jest.fn();
- const { getByPlaceholder } = render(
+ const { getByPlaceholderText } = render(
// MyComponent renders TextInput which has a placeholder 'Enter details'
// and with `onChangeText` bound to handleChangeText
);
- fireEvent(getByPlaceholder('change'), 'onChangeText', 'ab');
+ fireEvent(getByPlaceholderText('change'), 'onChangeText', 'ab');
expect(onEventMock).toHaveBeenCalledWith('ab');
});
```
@@ -196,14 +196,14 @@ import { fireEvent, render } from 'react-native-testing-library';
const onBlurMock = jest.fn();
-const { getByPlaceholder } = render(
+const { getByPlaceholderText } = render(
);
// you can omit the `on` prefix
-fireEvent(getByPlaceholder('my placeholder'), 'blur');
+fireEvent(getByPlaceholderText('my placeholder'), 'blur');
```
## `fireEvent[eventName]`
@@ -247,13 +247,13 @@ import { render, fireEvent } from 'react-native-testing-library';
const onChangeTextMock = jest.fn();
const CHANGE_TEXT = 'content';
-const { getByPlaceholder } = render(
+const { getByPlaceholderText } = render(
);
-fireEvent.changeText(getByPlaceholder('Enter data'), CHANGE_TEXT);
+fireEvent.changeText(getByPlaceholderText('Enter data'), CHANGE_TEXT);
```
### `fireEvent.scroll: (element: ReactTestInstance, ...data: Array) => void`
diff --git a/website/docs/MigrationV2.md b/website/docs/MigrationV2.md
index 84acf2a0a..067072399 100644
--- a/website/docs/MigrationV2.md
+++ b/website/docs/MigrationV2.md
@@ -114,7 +114,7 @@ In v2 we fixed this inconsistency, which may result in failing tests, if you rel
- use safe queries like `*ByText` or `*ByA11yHint`
:::caution
-In general, you should avoid `*byTestId` queries when possible. Use queries that check things that the user can interact with. Like `*ByText` or `*ByPlaceholder` or accessibility queries (e.g. `*ByA11yHint`, `*ByA11yLabel`).
+In general, you should avoid `*byTestId` queries when possible. Use queries that check things that the user can interact with. Like `*ByText` or `*ByPlaceholderText` or accessibility queries (e.g. `*ByA11yHint`, `*ByA11yLabel`).
:::
## Deprecated `flushMicrotasksQueue`
diff --git a/website/docs/Queries.md b/website/docs/Queries.md
index 756c97cb8..b59b4d3ec 100644
--- a/website/docs/Queries.md
+++ b/website/docs/Queries.md
@@ -68,17 +68,17 @@ const { getByText } = render();
const element = getByText('banana');
```
-### `ByPlaceholder`
+### `ByPlaceholderText`
-> getByPlaceholder, getAllByPlaceholder, queryByPlaceholder, queryAllByPlaceholder, findByPlaceholder, findAllByPlaceholder
+> getByPlaceholderText, getAllByPlaceholderText, queryByPlaceholderText, queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText
Returns a `ReactTestInstance` for a `TextInput` with a matching placeholder – may be a string or regular expression.
```jsx
import { render } from 'react-native-testing-library';
-const { getByPlaceholder } = render();
-const element = getByPlaceholder('username');
+const { getByPlaceholderText } = render();
+const element = getByPlaceholderText('username');
```
### `ByDisplayValue`
diff --git a/website/docs/ReduxIntegration.md b/website/docs/ReduxIntegration.md
index 20d6975df..349922426 100644
--- a/website/docs/ReduxIntegration.md
+++ b/website/docs/ReduxIntegration.md
@@ -32,11 +32,11 @@ describe('AddTodo component test', () => {
);
- const { getByPlaceholder, getByText } = render(component);
+ const { getByPlaceholderText, getByText } = render(component);
// There is a TextInput.
// https://github.com/callstack/react-native-testing-library/blob/ae3d4af370487e1e8fedd8219f77225690aefc59/examples/redux/components/AddTodo.js#L24
- const input = getByPlaceholder(/repository/i);
+ const input = getByPlaceholderText(/repository/i);
expect(input).toBeTruthy();
const textToEnter = 'This is a random element';