Skip to content

Commit ade9f33

Browse files
refactor: remove legacy wait for options support (#1018)
1 parent 980b3df commit ade9f33

File tree

2 files changed

+12
-81
lines changed

2 files changed

+12
-81
lines changed

src/queries/__tests__/text.test.tsx

-33
Original file line numberDiff line numberDiff line change
@@ -116,39 +116,6 @@ test('findByText queries work asynchronously', async () => {
116116
await expect(findAllByText('Some Text')).resolves.toHaveLength(1);
117117
}, 20000);
118118

119-
describe('findBy options deprecations', () => {
120-
let warnSpy: jest.SpyInstance;
121-
beforeEach(() => {
122-
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
123-
});
124-
afterEach(() => {
125-
warnSpy.mockRestore();
126-
});
127-
128-
test('findByText queries warn on deprecated use of WaitForOptions', async () => {
129-
const options = { timeout: 10 };
130-
// mock implementation to avoid warning in the test suite
131-
const { rerender, findByText } = render(<View />);
132-
await expect(findByText('Some Text', options)).rejects.toBeTruthy();
133-
134-
setTimeout(
135-
() =>
136-
rerender(
137-
<View>
138-
<Text>Some Text</Text>
139-
</View>
140-
),
141-
20
142-
);
143-
144-
await expect(findByText('Some Text')).resolves.toBeTruthy();
145-
146-
expect(warnSpy).toHaveBeenCalledWith(
147-
expect.stringContaining('Use of option "timeout"')
148-
);
149-
}, 20000);
150-
});
151-
152119
test('getByText works properly with custom text component', () => {
153120
function BoldText({ children }: ChildrenProps) {
154121
return <Text>{children}</Text>;

src/queries/makeQueries.ts

+12-48
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ export type QueryAllByQuery<Predicate, Options = void> = (
2525

2626
export type FindByQuery<Predicate, Options = void> = (
2727
predicate: Predicate,
28-
options?: Options & WaitForOptions,
28+
options?: Options,
2929
waitForOptions?: WaitForOptions
3030
) => Promise<ReactTestInstance>;
3131

3232
export type FindAllByQuery<Predicate, Options = void> = (
3333
predicate: Predicate,
34-
options?: Options & WaitForOptions,
34+
options?: Options,
3535
waitForOptions?: WaitForOptions
3636
) => Promise<ReactTestInstance[]>;
3737

@@ -46,36 +46,6 @@ export type UnboundQueries<Predicate, Options> = {
4646
findAllBy: UnboundQuery<FindAllByQuery<Predicate, Options>>;
4747
};
4848

49-
// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
50-
// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
51-
const deprecatedKeys: (keyof WaitForOptions)[] = [
52-
'timeout',
53-
'interval',
54-
'stackTraceError',
55-
];
56-
const extractDeprecatedWaitForOptionUsage = (queryOptions?: WaitForOptions) => {
57-
if (queryOptions) {
58-
const waitForOptions: WaitForOptions = {
59-
timeout: queryOptions.timeout,
60-
interval: queryOptions.interval,
61-
stackTraceError: queryOptions.stackTraceError,
62-
};
63-
deprecatedKeys.forEach((key) => {
64-
const option = queryOptions[key];
65-
if (option) {
66-
// eslint-disable-next-line no-console
67-
console.warn(
68-
`Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
69-
Example:
70-
71-
findByText(text, {}, { ${key}: ${option.toString()} })`
72-
);
73-
}
74-
});
75-
return waitForOptions;
76-
}
77-
};
78-
7949
export function makeQueries<Predicate, Options>(
8050
queryAllByQuery: UnboundQuery<QueryAllByQuery<Predicate, Options>>,
8151
getMissingError: (predicate: Predicate) => string,
@@ -128,32 +98,26 @@ export function makeQueries<Predicate, Options>(
12898
function findAllByQuery(instance: ReactTestInstance) {
12999
return function findAllFn(
130100
predicate: Predicate,
131-
queryOptions?: Options & WaitForOptions,
132-
waitForOptions: WaitForOptions = {}
101+
queryOptions?: Options,
102+
waitForOptions?: WaitForOptions
133103
) {
134-
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
135-
queryOptions
104+
return waitFor(
105+
() => getAllByQuery(instance)(predicate, queryOptions),
106+
waitForOptions
136107
);
137-
return waitFor(() => getAllByQuery(instance)(predicate, queryOptions), {
138-
...deprecatedWaitForOptions,
139-
...waitForOptions,
140-
});
141108
};
142109
}
143110

144111
function findByQuery(instance: ReactTestInstance) {
145112
return function findFn(
146113
predicate: Predicate,
147-
queryOptions?: Options & WaitForOptions,
148-
waitForOptions: WaitForOptions = {}
114+
queryOptions?: Options,
115+
waitForOptions?: WaitForOptions
149116
) {
150-
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
151-
queryOptions
117+
return waitFor(
118+
() => getByQuery(instance)(predicate, queryOptions),
119+
waitForOptions
152120
);
153-
return waitFor(() => getByQuery(instance)(predicate, queryOptions), {
154-
...deprecatedWaitForOptions,
155-
...waitForOptions,
156-
});
157121
};
158122
}
159123

0 commit comments

Comments
 (0)