Skip to content

Commit b4bf289

Browse files
committed
refactor types
1 parent eee4b71 commit b4bf289

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/helpers/findByAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const makeFindQuery = <Text, Result>(
2121
): Promise<Result> => waitFor(() => getQuery(instance)(text), waitForOptions);
2222

2323
export const findByTestId = (instance: ReactTestInstance) => (
24-
testId: string,
24+
testId: string | RegExp,
2525
waitForOptions: WaitForOptions = {}
2626
) => makeFindQuery(instance, getByTestId, testId, waitForOptions);
2727

src/helpers/getByAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const getByDisplayValue = (instance: ReactTestInstance) =>
134134
};
135135

136136
export const getByTestId = (instance: ReactTestInstance) =>
137-
function getByTestIdFn(testID: string) {
137+
function getByTestIdFn(testID: string | RegExp) {
138138
try {
139139
const results = getAllByTestId(instance)(testID);
140140
if (results.length === 1) {

src/helpers/queryByAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const queryByDisplayValue = (instance: ReactTestInstance) =>
4848
};
4949

5050
export const queryByTestId = (instance: ReactTestInstance) =>
51-
function queryByTestIdFn(testID: string) {
51+
function queryByTestIdFn(testID: string | RegExp) {
5252
try {
5353
return getByTestId(instance)(testID);
5454
} catch (error) {

typings/__tests__/index.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const getBy: ReactTestInstance[] = [
4141
tree.getByDisplayValue('my value'),
4242
tree.getByDisplayValue(/value/g),
4343
tree.getByTestId('test-id'),
44+
tree.getByTestId(/test-id/),
4445
tree.getByA11yLabel('label'),
4546
tree.getByLabelText('label'),
4647
tree.getByA11yHint('label'),
@@ -89,6 +90,7 @@ const queryBy: Array<ReactTestInstance | null> = [
8990
tree.queryByDisplayValue('my value'),
9091
tree.queryByDisplayValue(/value/g),
9192
tree.queryByTestId('test-id'),
93+
tree.queryByTestId(/test-id/),
9294
tree.queryByA11yHint('label'),
9395
tree.queryByHintText('label'),
9496
tree.queryByA11yLabel('label'),
@@ -112,7 +114,7 @@ const queryAllBy: ReactTestInstance[][] = [
112114
tree.queryAllByDisplayValue('my value'),
113115
tree.queryAllByDisplayValue(/value/g),
114116
tree.queryAllByTestId('test-id'),
115-
tree.queryAllByTestId(/value/),
117+
tree.queryAllByTestId(/test-id/),
116118
tree.queryAllByA11yLabel('label'),
117119
tree.queryAllByLabelText('label'),
118120
tree.queryAllByA11yHint('label'),
@@ -143,7 +145,7 @@ const findBy: Promise<ReactTestInstance>[] = [
143145
tree.findByDisplayValue(/value/g),
144146
tree.findByDisplayValue(/value/g, { timeout: 10, interval: 10 }),
145147
tree.findByTestId('test-id'),
146-
tree.findByTestId('test-id', { timeout: 10, interval: 10 }),
148+
tree.findByTestId(/test-id/, { timeout: 10, interval: 10 }),
147149
tree.findByA11yLabel('label'),
148150
tree.findByA11yLabel('label', { timeout: 10, interval: 10 }),
149151
tree.findByLabelText('label'),
@@ -179,7 +181,7 @@ const findAllBy: Promise<ReactTestInstance[]>[] = [
179181
tree.findAllByDisplayValue(/View/g),
180182
tree.findAllByDisplayValue(/View/g, { timeout: 10, interval: 10 }),
181183
tree.findAllByTestId('test-id'),
182-
tree.findAllByTestId(/value/, { timeout: 10, interval: 10 }),
184+
tree.findAllByTestId(/test-id/, { timeout: 10, interval: 10 }),
183185
tree.findAllByA11yLabel('label'),
184186
tree.findAllByA11yLabel('label', { timeout: 10, interval: 10 }),
185187
tree.findAllByLabelText('label'),

typings/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface GetByAPI {
1818
getByText: (text: string | RegExp) => ReactTestInstance;
1919
getByPlaceholderText: (placeholder: string | RegExp) => ReactTestInstance;
2020
getByDisplayValue: (value: string | RegExp) => ReactTestInstance;
21-
getByTestId: (testID: string) => ReactTestInstance;
21+
getByTestId: (testID: string | RegExp) => ReactTestInstance;
2222
getAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>;
2323
getAllByText: (text: string | RegExp) => Array<ReactTestInstance>;
2424
getAllByPlaceholderText: (
@@ -69,7 +69,7 @@ interface QueryByAPI {
6969
placeholder: string | RegExp
7070
) => ReactTestInstance | null;
7171
queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null;
72-
queryByTestId: (testID: string) => ReactTestInstance | null;
72+
queryByTestId: (testID: string | RegExp) => ReactTestInstance | null;
7373
queryAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance> | [];
7474
queryAllByText: (text: string | RegExp) => Array<ReactTestInstance> | [];
7575
queryAllByPlaceholderText: (
@@ -137,7 +137,7 @@ interface FindByAPI {
137137
value: string | RegExp,
138138
waitForOptions?: WaitForOptions
139139
) => FindReturn;
140-
findByTestId: (testID: string, waitForOptions?: WaitForOptions) => FindReturn;
140+
findByTestId: (testID: string | RegExp, waitForOptions?: WaitForOptions) => FindReturn;
141141
findAllByText: (
142142
text: string | RegExp,
143143
waitForOptions?: WaitForOptions

0 commit comments

Comments
 (0)