;
// Unsafe aliases
- UNSAFE_getByType: (type: React.ComponentType
) => ReactTestInstance,
+ UNSAFE_getByType:
(type: React.ComponentType
) => ReactTestInstance;
UNSAFE_getAllByType:
(
type: React.ComponentType
- ) => Array,
- UNSAFE_getByProps: (props: { [string]: any }) => ReactTestInstance,
- UNSAFE_getAllByProps: (props: { [string]: any }) => Array,
-
- getByName: () => void,
- getByType: () => void,
- getByProps: () => void,
- getAllByName: () => void,
- getAllByType: () => void,
- getAllByProps: () => void,
-
- getByPlaceholder: () => void,
- getAllByPlaceholder: () => void,
-|};
+ ) => Array;
+ UNSAFE_getByProps: (props: { [key: string]: any }) => ReactTestInstance;
+ UNSAFE_getAllByProps: (props: {
+ [key: string]: any;
+ }) => Array;
+};
export const UNSAFE_getByType = (
instance: ReactTestInstance
@@ -131,27 +119,4 @@ export const getByAPI = (instance: ReactTestInstance): GetByAPI => ({
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'
- ),
-
- // Renamed
- getByPlaceholder: () =>
- throwRenamedFunctionError('getByPlaceholder', 'getByPlaceholderText'),
- getAllByPlaceholder: () =>
- throwRenamedFunctionError('getAllByPlaceholder', 'getByPlaceholderText'),
});
diff --git a/src/helpers/makeA11yQuery.js b/src/helpers/makeA11yQuery.ts
similarity index 86%
rename from src/helpers/makeA11yQuery.js
rename to src/helpers/makeA11yQuery.ts
index fff34e8f9..658f36f96 100644
--- a/src/helpers/makeA11yQuery.js
+++ b/src/helpers/makeA11yQuery.ts
@@ -1,4 +1,4 @@
-// @flow
+import type { ReactTestInstance } from 'react-test-renderer';
import waitFor from '../waitFor';
import type { WaitForOptions } from '../waitFor';
import {
@@ -18,21 +18,19 @@ function makeAliases(aliases: Array, query: Function) {
}
type QueryNames = {
- getBy: Array,
- getAllBy: Array,
- queryBy: Array,
- queryAllBy: Array,
- findBy: Array,
- findAllBy: Array,
+ getBy: Array;
+ getAllBy: Array;
+ queryBy: Array;
+ queryAllBy: Array;
+ findBy: Array;
+ findAllBy: Array;
};
-const makeA11yQuery = (
+const makeA11yQuery = (
name: string,
queryNames: QueryNames,
matcherFn: (prop: P, value: M) => boolean
-): ((instance: ReactTestInstance) => { ... }) => (
- instance: ReactTestInstance
-) => {
+) => (instance: ReactTestInstance) => {
const getBy = (matcher: M) => {
try {
return instance.find(
diff --git a/src/helpers/makeQueries.js b/src/helpers/makeQueries.ts
similarity index 90%
rename from src/helpers/makeQueries.js
rename to src/helpers/makeQueries.ts
index 5d0a4e1ce..78dd61661 100644
--- a/src/helpers/makeQueries.js
+++ b/src/helpers/makeQueries.ts
@@ -1,4 +1,4 @@
-// @flow
+import type { ReactTestInstance } from 'react-test-renderer';
import waitFor from '../waitFor';
import type { WaitForOptions } from '../waitFor';
import { ErrorWithStack } from './errors';
@@ -35,16 +35,16 @@ type FindAllByQuery = FindQueryFunction<
type FindByQuery = FindQueryFunction;
export type Queries = {
- getBy: GetByQuery,
- getAllBy: GetAllByQuery,
- queryBy: QueryByQuery,
- findBy: FindByQuery,
- findAllBy: FindAllByQuery,
+ getBy: GetByQuery;
+ getAllBy: GetAllByQuery;
+ queryBy: QueryByQuery;
+ findBy: FindByQuery;
+ findAllBy: FindAllByQuery;
};
// The WaitForOptions has been moved to the second option param of findBy* methods with the adding of TextMatchOptions
// To make the migration easier and avoid a breaking change, keep reading this options from the first param but warn
-const deprecatedKeys: $Keys[] = [
+const deprecatedKeys: (keyof WaitForOptions)[] = [
'timeout',
'interval',
'stackTraceError',
@@ -57,13 +57,14 @@ const extractDeprecatedWaitForOptionUsage = (queryOptions?: WaitForOptions) => {
stackTraceError: queryOptions.stackTraceError,
};
deprecatedKeys.forEach((key) => {
- if (queryOptions[key]) {
+ const option = queryOptions[key];
+ if (option) {
// eslint-disable-next-line no-console
console.warn(
`Use of option "${key}" in a findBy* query's second parameter, TextMatchOptions, is deprecated. Please pass this option in the third, WaitForOptions, parameter.
Example:
- findByText(text, {}, { ${key}: ${queryOptions[key].toString()} })`
+ findByText(text, {}, { ${key}: ${option.toString()} })`
);
}
});
@@ -127,7 +128,7 @@ export function makeQueries(
return function findAllFn(
args: QueryArg,
queryOptions?: TextMatchOptions & WaitForOptions,
- waitForOptions?: WaitForOptions = {}
+ waitForOptions: WaitForOptions = {}
) {
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
queryOptions
@@ -143,7 +144,7 @@ export function makeQueries(
return function findFn(
args: QueryArg,
queryOptions?: TextMatchOptions & WaitForOptions,
- waitForOptions?: WaitForOptions = {}
+ waitForOptions: WaitForOptions = {}
) {
const deprecatedWaitForOptions = extractDeprecatedWaitForOptionUsage(
queryOptions
diff --git a/src/helpers/queryByAPI.js b/src/helpers/queryByAPI.ts
similarity index 78%
rename from src/helpers/queryByAPI.js
rename to src/helpers/queryByAPI.ts
index 064bb3cc8..12f73ecc5 100644
--- a/src/helpers/queryByAPI.js
+++ b/src/helpers/queryByAPI.ts
@@ -1,5 +1,6 @@
-// @flow
+import type { ReactTestInstance } from 'react-test-renderer';
import * as React from 'react';
+import type { TextMatch } from '../matches';
import type { TextMatchOptions } from './byText';
import {
UNSAFE_getByType,
@@ -20,55 +21,57 @@ import {
throwRenamedFunctionError,
} from './errors';
-export type QueryByAPI = {|
+export type QueryByAPI = {
queryByText: (
- name: string | RegExp,
+ name: TextMatch,
queryOptions?: TextMatchOptions
- ) => ReactTestInstance | null,
+ ) => ReactTestInstance | null;
queryAllByText: (
- text: string | RegExp,
+ text: TextMatch,
queryOptions?: TextMatchOptions
- ) => Array,
+ ) => Array;
queryByPlaceholderText: (
- placeholder: string | RegExp,
+ placeholder: TextMatch,
queryOptions?: TextMatchOptions
- ) => ReactTestInstance | null,
+ ) => ReactTestInstance | null;
queryAllByPlaceholderText: (
- placeholder: string | RegExp,
+ placeholder: TextMatch,
queryOptions?: TextMatchOptions
- ) => Array,
+ ) => Array;
queryByDisplayValue: (
- value: string | RegExp,
+ value: TextMatch,
queryOptions?: TextMatchOptions
- ) => ReactTestInstance | null,
+ ) => ReactTestInstance | null;
queryAllByDisplayValue: (
- value: string | RegExp,
+ value: TextMatch,
queryOptions?: TextMatchOptions
- ) => Array,
- queryByTestId: (testID: string | RegExp) => ReactTestInstance | null,
- queryAllByTestId: (testID: string | RegExp) => Array,
+ ) => Array;
+ queryByTestId: (testID: TextMatch) => ReactTestInstance | null;
+ queryAllByTestId: (testID: TextMatch) => Array;
// Unsafe aliases
UNSAFE_queryByType: (
type: React.ComponentType
- ) => ReactTestInstance | null,
+ ) => ReactTestInstance | null;
UNSAFE_queryAllByType:
(
type: React.ComponentType
- ) => Array,
- UNSAFE_queryByProps: (props: { [string]: any }) => ReactTestInstance | null,
+ ) => Array;
+ UNSAFE_queryByProps: (props: {
+ [key: string]: any;
+ }) => ReactTestInstance | null;
UNSAFE_queryAllByProps: (props: {
- [string]: any,
- }) => Array,
- queryByName: () => void,
- queryByType: () => void,
- queryByProps: () => void,
- queryAllByName: () => void,
- queryAllByType: () => void,
- queryAllByProps: () => void,
+ [key: string]: any;
+ }) => Array;
+ queryByName: () => void;
+ queryByType: () => void;
+ queryByProps: () => void;
+ queryAllByName: () => void;
+ queryAllByType: () => void;
+ queryAllByProps: () => void;
- queryByPlaceholder: () => void,
- queryAllByPlaceholder: () => void,
-|};
+ queryByPlaceholder: () => void;
+ queryAllByPlaceholder: () => void;
+};
export const UNSAFE_queryByType = (
instance: ReactTestInstance
@@ -107,7 +110,7 @@ export const UNSAFE_queryAllByType = (
export const UNSAFE_queryAllByProps = (
instance: ReactTestInstance
): ((props: {
- [propName: string]: any,
+ [propName: string]: any;
}) => Array) => (props: { [propName: string]: any }) => {
try {
return UNSAFE_getAllByProps(instance)(props);
diff --git a/src/helpers/timers.js b/src/helpers/timers.ts
similarity index 82%
rename from src/helpers/timers.js
rename to src/helpers/timers.ts
index 95868d683..e140e991a 100644
--- a/src/helpers/timers.js
+++ b/src/helpers/timers.ts
@@ -1,7 +1,5 @@
// Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
-// @flow
/* globals jest */
-
const globalObj = typeof window === 'undefined' ? global : window;
// Currently this fn only supports jest timers, but it could support other test runners in the future.
@@ -30,20 +28,21 @@ function getJestFakeTimersType() {
}
if (
+ // @ts-expect-error jest mutates setTimeout
typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&
+ // @ts-expect-error jest mutates setTimeout
globalObj.setTimeout._isMockFunction
) {
return 'legacy';
}
if (
+ // @ts-expect-error jest mutates setTimeout
typeof globalObj.setTimeout.clock !== 'undefined' &&
- // $FlowIgnore[prop-missing]
typeof jest.getRealSystemTime !== 'undefined'
) {
try {
// jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
- // $FlowExpectedError
jest.getRealSystemTime();
return 'modern';
} catch {
@@ -57,14 +56,14 @@ const jestFakeTimersAreEnabled = (): boolean =>
Boolean(getJestFakeTimersType());
// we only run our tests in node, and setImmediate is supported in node.
-function setImmediatePolyfill(fn) {
+function setImmediatePolyfill(fn: Function) {
return globalObj.setTimeout(fn, 0);
}
type BindTimeFunctions = {
- clearTimeoutFn: typeof clearTimeout,
- setImmediateFn: typeof setImmediate,
- setTimeoutFn: typeof setTimeout,
+ clearTimeoutFn: typeof clearTimeout;
+ setImmediateFn: typeof setImmediate;
+ setTimeoutFn: typeof setTimeout;
};
function bindTimeFunctions(): BindTimeFunctions {
@@ -75,9 +74,9 @@ function bindTimeFunctions(): BindTimeFunctions {
};
}
-const { clearTimeoutFn, setImmediateFn, setTimeoutFn } = (runWithRealTimers(
+const { clearTimeoutFn, setImmediateFn, setTimeoutFn } = runWithRealTimers(
bindTimeFunctions
-): BindTimeFunctions);
+) as BindTimeFunctions;
export {
runWithRealTimers,
diff --git a/src/index.js b/src/index.ts
similarity index 98%
rename from src/index.js
rename to src/index.ts
index d4cb964e8..a8bc65b9f 100644
--- a/src/index.js
+++ b/src/index.ts
@@ -1,4 +1,3 @@
-// @flow
import { cleanup } from './pure';
import { flushMicroTasks } from './flushMicroTasks';
diff --git a/src/matches.js b/src/matches.ts
similarity index 81%
rename from src/matches.js
rename to src/matches.ts
index b5cfcd74c..1783dec35 100644
--- a/src/matches.js
+++ b/src/matches.ts
@@ -1,11 +1,11 @@
-// @flow
export type NormalizerFn = (textToNormalize: string) => string;
+export type TextMatch = string | RegExp;
export function matches(
- matcher: string | RegExp,
+ matcher: TextMatch,
text: string,
- normalizer?: NormalizerFn = getDefaultNormalizer(),
- exact?: boolean = true
+ normalizer: NormalizerFn = getDefaultNormalizer(),
+ exact: boolean = true
): boolean {
if (typeof text !== 'string') {
return false;
@@ -22,8 +22,8 @@ export function matches(
}
type NormalizerConfig = {
- trim?: boolean,
- collapseWhitespace?: boolean,
+ trim?: boolean;
+ collapseWhitespace?: boolean;
};
export function getDefaultNormalizer({
diff --git a/src/pure.js b/src/pure.ts
similarity index 67%
rename from src/pure.js
rename to src/pure.ts
index 61d9c5414..9baffa97f 100644
--- a/src/pure.js
+++ b/src/pure.ts
@@ -1,11 +1,8 @@
-// @flow
import act from './act';
import cleanup from './cleanup';
import fireEvent from './fireEvent';
-import flushMicrotasksQueue from './flushMicroTasks';
import render from './render';
-import shallow from './shallow';
-import waitFor, { waitForElement } from './waitFor';
+import waitFor from './waitFor';
import waitForElementToBeRemoved from './waitForElementToBeRemoved';
import { within, getQueriesForElement } from './within';
import { getDefaultNormalizer } from './matches';
@@ -13,10 +10,8 @@ import { getDefaultNormalizer } from './matches';
export { act };
export { cleanup };
export { fireEvent };
-export { flushMicrotasksQueue };
export { render };
-export { shallow };
-export { waitFor, waitForElement };
+export { waitFor };
export { waitForElementToBeRemoved };
export { within, getQueriesForElement };
export { getDefaultNormalizer };
diff --git a/src/render.js b/src/render.tsx
similarity index 57%
rename from src/render.js
rename to src/render.tsx
index e6323d58d..1f446900a 100644
--- a/src/render.js
+++ b/src/render.tsx
@@ -1,21 +1,21 @@
-// @flow
+import TestRenderer from 'react-test-renderer';
+import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer';
import * as React from 'react';
-import TestRenderer, { type ReactTestRenderer } from 'react-test-renderer'; // eslint-disable-line import/no-extraneous-dependencies
import act from './act';
import { addToCleanupQueue } from './cleanup';
-import { getByAPI, type GetByAPI } from './helpers/getByAPI';
-import { queryByAPI, type QueryByAPI } from './helpers/queryByAPI';
-import { findByAPI, type FindByAPI } from './helpers/findByAPI';
-import { a11yAPI, type A11yAPI } from './helpers/a11yAPI';
+import { getByAPI } from './helpers/getByAPI';
+import { queryByAPI } from './helpers/queryByAPI';
+import { findByAPI } from './helpers/findByAPI';
+import { a11yAPI } from './helpers/a11yAPI';
import debugShallow from './helpers/debugShallow';
import debugDeep from './helpers/debugDeep';
type Options = {
- wrapper?: React.ComponentType,
- createNodeMock?: (element: React.Element) => any,
+ wrapper?: React.ComponentType;
+ createNodeMock?: (element: React.ReactElement) => any;
};
type TestRendererOptions = {
- createNodeMock: (element: React.Element) => any,
+ createNodeMock: (element: React.ReactElement) => any;
};
/**
@@ -23,21 +23,10 @@ type TestRendererOptions = {
* to assert on the output.
*/
export default function render(
- component: React.Element,
+ component: React.ReactElement,
{ wrapper: Wrapper, createNodeMock }: Options = {}
-): {
- ...FindByAPI,
- ...QueryByAPI,
- ...GetByAPI,
- ...A11yAPI,
- update: (component: React.Element) => void,
- container: ReactTestInstance,
- rerender: (component: React.Element) => void,
- unmount: (nextElement?: React.Element) => void,
- toJSON: () => null | ReactTestRendererJSON,
- debug: DebugFunction,
-} {
- const wrap = (innerElement: React.Element) =>
+) {
+ const wrap = (innerElement: React.ReactElement) =>
Wrapper ? {innerElement} : innerElement;
const renderer = renderWithAct(
@@ -69,7 +58,7 @@ export default function render(
}
function renderWithAct(
- component: React.Element,
+ component: React.ReactElement,
options?: TestRendererOptions
): ReactTestRenderer {
let renderer: ReactTestRenderer;
@@ -78,14 +67,15 @@ function renderWithAct(
renderer = TestRenderer.create(component, options);
});
- return ((renderer: any): ReactTestRenderer);
+ // @ts-ignore act is sync, so renderer is always initialised here
+ return renderer;
}
function updateWithAct(
renderer: ReactTestRenderer,
- wrap: (innerElement: React.Element) => React.Element
+ wrap: (innerElement: React.ReactElement) => React.ReactElement
) {
- return function (component: React.Element) {
+ return function (component: React.ReactElement) {
act(() => {
renderer.update(wrap(component));
});
@@ -102,8 +92,11 @@ function debug(
renderer: ReactTestRenderer
): DebugFunction {
function debugImpl(message?: string) {
- return debugDeep(renderer.toJSON(), message);
+ const json = renderer.toJSON();
+ if (json) {
+ return debugDeep(json, message);
+ }
}
- debugImpl.shallow = (message) => debugShallow(instance, message);
+ debugImpl.shallow = (message?: string) => debugShallow(instance, message);
return debugImpl;
}
diff --git a/src/shallow.js b/src/shallow.ts
similarity index 51%
rename from src/shallow.js
rename to src/shallow.ts
index d3fecd0c3..bc5ae0993 100644
--- a/src/shallow.js
+++ b/src/shallow.ts
@@ -1,15 +1,14 @@
-// @flow
import * as React from 'react';
+import { ReactTestInstance } from 'react-test-renderer';
import ShallowRenderer from 'react-test-renderer/shallow'; // eslint-disable-line import/no-extraneous-dependencies
-import { throwRemovedFunctionError } from './helpers/errors';
/**
* Renders test component shallowly using react-test-renderer/shallow
*/
export function shallowInternal(
- instance: ReactTestInstance | React.Element
-): {| output: any |} {
- const renderer = new ShallowRenderer();
+ instance: ReactTestInstance | React.ReactElement
+): { output: any } {
+ const renderer = new (ShallowRenderer as any)();
renderer.render(React.createElement(instance.type, instance.props));
@@ -17,10 +16,3 @@ export function shallowInternal(
output: renderer.getRenderOutput(),
};
}
-
-export default function shallow(_: ReactTestInstance | React.Element) {
- throwRemovedFunctionError(
- 'shallow',
- 'migration-v2#removed-global-shallow-function'
- );
-}
diff --git a/src/types.flow.js b/src/types.flow.js
deleted file mode 100644
index c48b5ed0e..000000000
--- a/src/types.flow.js
+++ /dev/null
@@ -1,59 +0,0 @@
-// @flow
-
-export type Thenable = {
- then(resolve: () => mixed, reject?: () => mixed): mixed,
-};
-
-export type A11yRole =
- | 'none'
- | 'button'
- | 'link'
- | 'search'
- | 'image'
- | 'keyboardkey'
- | 'text'
- | 'adjustable'
- | 'imagebutton'
- | 'header'
- | 'summary'
- | 'alert'
- | 'checkbox'
- | 'combobox'
- | 'menu'
- | 'menubar'
- | 'menuitem'
- | 'progressbar'
- | 'radio'
- | 'radiogroup'
- | 'scrollbar'
- | 'spinbutton'
- | 'switch'
- | 'tab'
- | 'tablist'
- | 'timer'
- | 'toolbar';
-
-export type A11yState = {|
- disabled?: boolean,
- selected?: boolean,
- checked?: boolean | 'mixed',
- busy?: boolean,
- expanded?: boolean,
-|};
-
-export type A11yStates =
- | 'disabled'
- | 'selected'
- | 'checked'
- | 'unchecked'
- | 'busy'
- | 'expanded'
- | 'collapsed'
- | 'hasPopup';
-
-export type A11yValue = {
- min?: number,
- max?: number,
- now?: number,
- text?: string,
-};
diff --git a/src/waitFor.js b/src/waitFor.ts
similarity index 85%
rename from src/waitFor.js
rename to src/waitFor.ts
index 3e5a881f0..35d42c7ad 100644
--- a/src/waitFor.js
+++ b/src/waitFor.ts
@@ -1,13 +1,7 @@
-// @flow
/* globals jest */
-
import * as React from 'react';
import act from './act';
-import {
- ErrorWithStack,
- throwRemovedFunctionError,
- copyStackTrace,
-} from './helpers/errors';
+import { ErrorWithStack, copyStackTrace } from './helpers/errors';
import {
setTimeout,
clearTimeout,
@@ -26,10 +20,10 @@ function checkReactVersionAtLeast(major: number, minor: number): boolean {
}
export type WaitForOptions = {
- timeout?: number,
- interval?: number,
- stackTraceError?: ErrorWithStack,
- onTimeout?: (error: Error) => Error,
+ timeout?: number;
+ interval?: number;
+ stackTraceError?: ErrorWithStack;
+ onTimeout?: (error: unknown) => Error;
};
function waitForInternal(
@@ -47,7 +41,7 @@ function waitForInternal(
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
- let lastError, intervalId;
+ let lastError: unknown, intervalId: ReturnType;
let finished = false;
let promiseStatus = 'idle';
@@ -107,7 +101,9 @@ function waitForInternal(
checkExpectation();
}
- function onDone(error, result) {
+ function onDone(
+ done: { type: 'result'; result: T } | { type: 'error'; error: unknown }
+ ) {
finished = true;
clearTimeout(overallTimeoutTimer);
@@ -115,11 +111,10 @@ function waitForInternal(
clearInterval(intervalId);
}
- if (error) {
- reject(error);
+ if (done.type === 'error') {
+ reject(done.error);
} else {
- // $FlowIgnore[incompatible-return] error and result are mutually exclusive
- resolve(result);
+ resolve(done.result);
}
}
@@ -142,14 +137,16 @@ function waitForInternal(
try {
const result = expectation();
- // $FlowIgnore[incompatible-type]
+ // @ts-ignore result can be a promise
+ // eslint-disable-next-line promise/prefer-await-to-then
if (typeof result?.then === 'function') {
+ const promiseResult: Promise = result as any;
promiseStatus = 'pending';
- // eslint-disable-next-line promise/catch-or-return
- result.then(
+ // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
+ promiseResult.then(
(resolvedValue) => {
promiseStatus = 'resolved';
- onDone(null, resolvedValue);
+ onDone({ type: 'result', result: resolvedValue });
return;
},
(rejectedValue) => {
@@ -159,7 +156,7 @@ function waitForInternal(
}
);
} else {
- onDone(null, result);
+ onDone({ type: 'result', result: result });
}
// If `callback` throws, wait for the next mutation, interval, or timeout.
} catch (error) {
@@ -184,7 +181,7 @@ function waitForInternal(
if (typeof onTimeout === 'function') {
onTimeout(error);
}
- onDone(error, null);
+ onDone({ type: 'error', error });
}
});
}
@@ -203,24 +200,10 @@ export default async function waitFor(
let result: T;
- //$FlowFixMe: `act` has incorrect flow typing
await act(async () => {
result = await waitForInternal(expectation, optionsWithStackTrace);
});
- //$FlowFixMe: either we have result or `waitFor` threw error
- return result;
-}
-
-export function waitForElement(
- expectation: () => T,
- _timeout: number = 4500,
- _interval: number = 50
-): Promise {
- throwRemovedFunctionError(
- 'waitForElement',
- 'migration-v2#waitfor-api-changes'
- );
-
- return Promise.reject();
+ // Either we have result or `waitFor` threw error
+ return result!;
}
diff --git a/src/waitForElementToBeRemoved.js b/src/waitForElementToBeRemoved.ts
similarity index 93%
rename from src/waitForElementToBeRemoved.js
rename to src/waitForElementToBeRemoved.ts
index fb3cc5bc4..9308bec25 100644
--- a/src/waitForElementToBeRemoved.js
+++ b/src/waitForElementToBeRemoved.ts
@@ -1,5 +1,5 @@
-// @flow
-import waitFor, { type WaitForOptions } from './waitFor';
+import waitFor from './waitFor';
+import type { WaitForOptions } from './waitFor';
import { ErrorWithStack } from './helpers/errors';
function isRemoved(result: T): boolean {
diff --git a/src/within.js b/src/within.js
deleted file mode 100644
index 9b54671e8..000000000
--- a/src/within.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// @flow
-import { getByAPI, type GetByAPI } from './helpers/getByAPI';
-import { queryByAPI, type QueryByAPI } from './helpers/queryByAPI';
-import { findByAPI, type FindByAPI } from './helpers/findByAPI';
-import { a11yAPI, type A11yAPI } from './helpers/a11yAPI';
-
-export function within(
- instance: ReactTestInstance
-): { ...FindByAPI, ...QueryByAPI, ...GetByAPI, ...A11yAPI } {
- return {
- ...getByAPI(instance),
- ...queryByAPI(instance),
- ...findByAPI(instance),
- ...a11yAPI(instance),
- };
-}
-
-export const getQueriesForElement = within;
diff --git a/src/within.ts b/src/within.ts
new file mode 100644
index 000000000..bfc6304a9
--- /dev/null
+++ b/src/within.ts
@@ -0,0 +1,16 @@
+import type { ReactTestInstance } from 'react-test-renderer';
+import { getByAPI } from './helpers/getByAPI';
+import { queryByAPI } from './helpers/queryByAPI';
+import { findByAPI } from './helpers/findByAPI';
+import { a11yAPI } from './helpers/a11yAPI';
+
+export function within(instance: ReactTestInstance) {
+ return {
+ ...getByAPI(instance),
+ ...queryByAPI(instance),
+ ...findByAPI(instance),
+ ...a11yAPI(instance),
+ };
+}
+
+export const getQueriesForElement = within;
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 000000000..620131f6b
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,17 @@
+{
+ "compilerOptions": {
+ "strict": true,
+ "esModuleInterop": true,
+ "allowSyntheticDefaultImports": true,
+ "skipLibCheck": true,
+ "jsx": "react",
+ "target": "ES2020",
+ "lib": ["ES2020", "DOM"],
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "declaration": true,
+ "noEmit": true,
+ "outDir": "build"
+ },
+ "include": ["src/**/*"]
+}
diff --git a/tsconfig.release.json b/tsconfig.release.json
new file mode 100644
index 000000000..7477c950f
--- /dev/null
+++ b/tsconfig.release.json
@@ -0,0 +1,8 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "noEmit": false,
+ "emitDeclarationOnly": true
+ },
+ "exclude": ["**/__tests__**"]
+}
diff --git a/typings/__tests__/index.test.tsx b/typings/__tests__/index.test.tsx
deleted file mode 100644
index 6cd6c558c..000000000
--- a/typings/__tests__/index.test.tsx
+++ /dev/null
@@ -1,486 +0,0 @@
-/* eslint-disable @typescript-eslint/no-unused-vars */
-import * as React from 'react';
-import { ReactTestInstance } from 'react-test-renderer';
-import {
- render,
- fireEvent,
- flushMicrotasksQueue,
- waitFor,
- waitForElementToBeRemoved,
- act,
- within,
- getQueriesForElement,
- getDefaultNormalizer,
-} from '../..';
-
-interface HasRequiredProp {
- requiredProp: string;
-}
-
-const View = (props) => props.children;
-const Text = (props) => props.children;
-const TextInput = (props) => props.children;
-const ElementWithRequiredProps = (props: HasRequiredProp) => (
- {props.requiredProp}
-);
-
-const TestComponent = () => (
-
- Test component
-
-
-);
-
-const tree = render();
-
-// getBy API
-const getBy: ReactTestInstance[] = [
- tree.getByText(''),
- tree.getByText(/View/g),
- tree.getByPlaceholderText('my placeholder'),
- tree.getByPlaceholderText(/placeholder/g),
- tree.getByDisplayValue('my value'),
- tree.getByDisplayValue(/value/g),
- tree.getByTestId('test-id'),
- tree.getByTestId(/test-id/),
- tree.getByA11yLabel('label'),
- tree.getByLabelText('label'),
- tree.getByA11yHint('label'),
- tree.getByHintText('label'),
- tree.getByA11yRole('button'),
- tree.getByRole('button'),
- tree.getByA11yStates('selected'),
- tree.getByA11yStates(['selected']),
- tree.getByA11yState({ busy: true }),
- tree.getByA11yValue({ min: 10 }),
- tree.UNSAFE_getByType(View),
- tree.UNSAFE_getByType(ElementWithRequiredProps),
- tree.UNSAFE_getByProps({ value: 2 }),
-];
-
-const getAllBy: ReactTestInstance[][] = [
- tree.getAllByText(''),
- tree.getAllByText(/Text/g),
- tree.getAllByPlaceholderText('my placeholder'),
- tree.getAllByPlaceholderText(/placeholder/g),
- tree.getAllByDisplayValue('my value'),
- tree.getAllByDisplayValue(/value/g),
- tree.getAllByTestId('test-id'),
- tree.getAllByTestId(/value/g),
- tree.getAllByA11yLabel('label'),
- tree.getAllByLabelText('label'),
- tree.getAllByA11yHint('label'),
- tree.getAllByHintText('label'),
- tree.getAllByA11yRole('button'),
- tree.getAllByRole('button'),
- tree.getAllByA11yStates('selected'),
- tree.getAllByA11yStates(['selected']),
- tree.getAllByA11yState({ busy: true }),
- tree.getAllByA11yValue({ min: 10 }),
- tree.UNSAFE_getAllByType(View),
- tree.UNSAFE_getAllByType(ElementWithRequiredProps),
- tree.UNSAFE_getAllByProps({ value: 2 }),
-];
-
-// queryBy API
-const queryBy: Array = [
- tree.queryByText('View'),
- tree.queryByText(/View/g),
- tree.queryByPlaceholderText('my placeholder'),
- tree.queryByPlaceholderText(/placeholder/g),
- tree.queryByDisplayValue('my value'),
- tree.queryByDisplayValue(/value/g),
- tree.queryByTestId('test-id'),
- tree.queryByTestId(/test-id/),
- tree.queryByA11yHint('label'),
- tree.queryByHintText('label'),
- tree.queryByA11yLabel('label'),
- tree.queryByLabelText('label'),
- tree.queryByA11yRole('button'),
- tree.queryByRole('button'),
- tree.queryByA11yStates('selected'),
- tree.queryByA11yStates(['selected']),
- tree.queryByA11yState({ busy: true }),
- tree.queryByA11yValue({ min: 10 }),
- tree.UNSAFE_queryByType(View),
- tree.UNSAFE_queryByType(ElementWithRequiredProps),
- tree.UNSAFE_queryByProps({ value: 2 }),
-];
-
-const queryAllBy: ReactTestInstance[][] = [
- tree.queryAllByText('View'),
- tree.queryAllByText(/View/g),
- tree.queryAllByPlaceholderText('my placeholder'),
- tree.queryAllByPlaceholderText(/placeholder/g),
- tree.queryAllByDisplayValue('my value'),
- tree.queryAllByDisplayValue(/value/g),
- tree.queryAllByTestId('test-id'),
- tree.queryAllByTestId(/test-id/),
- tree.queryAllByA11yLabel('label'),
- tree.queryAllByLabelText('label'),
- tree.queryAllByA11yHint('label'),
- tree.queryAllByHintText('label'),
- tree.queryAllByA11yRole('button'),
- tree.queryAllByRole('button'),
- tree.queryAllByA11yStates('selected'),
- tree.queryAllByA11yStates(['selected']),
- tree.queryAllByA11yState({ busy: true }),
- tree.queryAllByA11yValue({ min: 10 }),
- tree.UNSAFE_queryAllByType(View),
- tree.UNSAFE_queryAllByType(ElementWithRequiredProps),
- tree.UNSAFE_queryAllByProps({ value: 2 }),
-];
-
-// findBy API
-const findBy: Promise[] = [
- tree.findByText('View'),
- tree.findByText('View', {}, { timeout: 10, interval: 10 }),
- tree.findByText(/View/g),
- tree.findByText(/View/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),
- tree.findByDisplayValue(/value/g, {}, { timeout: 10, interval: 10 }),
- tree.findByTestId('test-id'),
- tree.findByTestId(/test-id/, {}, { timeout: 10, interval: 10 }),
- tree.findByA11yLabel('label'),
- tree.findByA11yLabel('label', { timeout: 10, interval: 10 }),
- tree.findByLabelText('label'),
- tree.findByLabelText('label', { timeout: 10, interval: 10 }),
- tree.findByA11yHint('label'),
- tree.findByA11yHint('label', { timeout: 10, interval: 10 }),
- tree.findByHintText('label'),
- tree.findByHintText('label', { timeout: 10, interval: 10 }),
- tree.findByA11yRole('button'),
- tree.findByA11yRole('button', { timeout: 10, interval: 10 }),
- tree.findByRole('button'),
- tree.findByRole('button', { timeout: 10, interval: 10 }),
- tree.findByA11yState({ busy: true }),
- tree.findByA11yState({ busy: true }, { timeout: 10, interval: 10 }),
- tree.findByA11yValue({ min: 10 }),
- tree.findByA11yValue({ min: 10 }, { timeout: 10, interval: 10 }),
-];
-
-const findAllBy: Promise[] = [
- tree.findAllByText('View'),
- tree.findAllByText('View', {}, { timeout: 10, interval: 10 }),
- tree.findAllByText(/View/g),
- tree.findAllByText(/View/g, { exact: false }, { timeout: 10, interval: 5 }),
- tree.findAllByPlaceholderText('my placeholder'),
- tree.findAllByPlaceholderText(
- 'my placeholder',
- { exact: false },
- {
- 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),
- tree.findAllByDisplayValue(/View/g, {}, { timeout: 10, interval: 10 }),
- tree.findAllByTestId('test-id'),
- tree.findAllByTestId(/test-id/, {}, { timeout: 10, interval: 10 }),
- tree.findAllByA11yLabel('label'),
- tree.findAllByA11yLabel('label', { timeout: 10, interval: 10 }),
- tree.findAllByLabelText('label'),
- tree.findAllByLabelText('label', { timeout: 10, interval: 10 }),
- tree.findAllByA11yHint('label'),
- tree.findAllByA11yHint('label', { timeout: 10, interval: 10 }),
- tree.findAllByHintText('label'),
- tree.findAllByHintText('label', { timeout: 10, interval: 10 }),
- tree.findAllByA11yState({ busy: true }),
- tree.findAllByA11yState({ busy: true }, { timeout: 10, interval: 10 }),
- tree.findAllByA11yValue({ min: 10 }),
- tree.findAllByA11yValue({ min: 10 }, { timeout: 10, interval: 10 }),
-];
-
-// debug API
-const debugFn = tree.debug();
-const debugFnWithMessage = tree.debug('my message');
-const shallowDebug = tree.debug.shallow();
-const shallowDebugWithMessage = tree.debug.shallow('my message');
-
-// update API
-tree.update();
-tree.rerender();
-tree.unmount();
-
-// fireEvent API
-const element: ReactTestInstance = tree.getByText('text');
-fireEvent(element, 'press');
-fireEvent(element, 'press', 'data');
-fireEvent(element, 'press', 'param1', 'param2');
-fireEvent.press(element);
-fireEvent.changeText(element, 'string');
-fireEvent.scroll(element, 'eventData');
-
-// waitFor API
-const timeout = { timeout: 10 };
-const timeoutInterval = { timeout: 100, interval: 10 };
-
-const waitGetBy: Promise[] = [
- waitFor(() => tree.getByA11yLabel('label')),
- waitFor(() => tree.getByA11yLabel('label'), timeout),
- waitFor(
- () => tree.getByA11yLabel('label'),
- timeoutInterval
- ),
-];
-
-const waitGetAllBy: Promise[] = [
- waitFor(() => tree.getAllByA11yLabel('label')),
- waitFor(() => tree.getAllByA11yLabel('label'), timeout),
- waitFor(
- () => tree.getAllByA11yLabel('label'),
- timeoutInterval
- ),
-];
-
-// waitForElementToBeRemoved API
-const waitForElementToBeRemovedGetBy: Promise[] = [
- waitForElementToBeRemoved(() => tree.getByText('text')),
- waitForElementToBeRemoved(
- () => tree.getByText('text'),
- timeout
- ),
- waitForElementToBeRemoved(
- () => tree.getByText('text'),
- timeoutInterval
- ),
-];
-const waitForElementToBeRemovedGetAllBy: Promise[] = [
- waitForElementToBeRemoved(() =>
- tree.getAllByText('text')
- ),
- waitForElementToBeRemoved(
- () => tree.getAllByText('text'),
- timeout
- ),
- waitForElementToBeRemoved(
- () => tree.getAllByText('text'),
- timeoutInterval
- ),
-];
-const waitForElementToBeRemovedQueryBy: Promise[] = [
- waitForElementToBeRemoved(() =>
- tree.queryByText('text')
- ),
- waitForElementToBeRemoved(
- () => tree.queryByText('text'),
- timeout
- ),
- waitForElementToBeRemoved(
- () => tree.queryByText('text'),
- timeoutInterval
- ),
-];
-const waitForElementToBeRemovedQueryAllBy: Promise[] = [
- waitForElementToBeRemoved(() =>
- tree.queryAllByText('text')
- ),
- waitForElementToBeRemoved(
- () => tree.queryAllByText('text'),
- timeout
- ),
- waitForElementToBeRemoved(
- () => tree.queryAllByText('text'),
- timeoutInterval
- ),
-];
-
-const waitForFlush: Promise = flushMicrotasksQueue();
-
-// act API
-act(() => {
- render();
-});
-
-// within API
-const instance: ReactTestInstance = tree.getByText('');
-
-const withinGet: Array = [
- within(instance).getByText('Test'),
- within(instance).getByDisplayValue('Test'),
- within(instance).getByPlaceholderText('Test'),
- within(instance).getByTestId('Test'),
- within(instance).getByA11yLabel('Test'),
- within(instance).getByLabelText('Test'),
- within(instance).getByA11yHint('Test'),
- within(instance).getByHintText('Test'),
- within(instance).getByA11yRole('button'),
- within(instance).getByRole('button'),
- within(instance).getByA11yState({ busy: true }),
- within(instance).getByA11yValue({ min: 10 }),
- getQueriesForElement(instance).getByText('Test'),
- getQueriesForElement(instance).getByDisplayValue('Test'),
- getQueriesForElement(instance).getByPlaceholderText('Test'),
- getQueriesForElement(instance).getByTestId('Test'),
- getQueriesForElement(instance).getByA11yLabel('Test'),
- getQueriesForElement(instance).getByLabelText('Test'),
- getQueriesForElement(instance).getByA11yHint('Test'),
- getQueriesForElement(instance).getByHintText('Test'),
- getQueriesForElement(instance).getByA11yRole('button'),
- getQueriesForElement(instance).getByRole('button'),
- getQueriesForElement(instance).getByA11yState({ busy: true }),
- getQueriesForElement(instance).getByA11yValue({ min: 10 }),
-];
-
-const withinGetAll: Array = [
- within(instance).getAllByText('Test'),
- within(instance).getAllByDisplayValue('Test'),
- within(instance).getAllByPlaceholderText('Test'),
- within(instance).getAllByTestId('Test'),
- within(instance).getAllByA11yLabel('Test'),
- within(instance).getAllByLabelText('button'),
- within(instance).getAllByA11yHint('Test'),
- within(instance).getAllByHintText('button'),
- within(instance).getAllByA11yRole('button'),
- within(instance).getAllByRole('button'),
- within(instance).getAllByA11yState({ busy: true }),
- within(instance).getAllByA11yValue({ min: 10 }),
- getQueriesForElement(instance).getAllByText('Test'),
- getQueriesForElement(instance).getAllByDisplayValue('Test'),
- getQueriesForElement(instance).getAllByPlaceholderText('Test'),
- getQueriesForElement(instance).getAllByTestId('Test'),
- getQueriesForElement(instance).getAllByA11yLabel('Test'),
- getQueriesForElement(instance).getAllByLabelText('button'),
- getQueriesForElement(instance).getAllByA11yHint('Test'),
- getQueriesForElement(instance).getAllByHintText('button'),
- getQueriesForElement(instance).getAllByA11yRole('button'),
- getQueriesForElement(instance).getAllByRole('button'),
- getQueriesForElement(instance).getAllByA11yState({ busy: true }),
- getQueriesForElement(instance).getAllByA11yValue({ min: 10 }),
-];
-
-const withinQuery: Array = [
- within(instance).queryByText('Test'),
- within(instance).queryByDisplayValue('Test'),
- within(instance).queryByPlaceholderText('Test'),
- within(instance).queryByTestId('Test'),
- within(instance).queryByA11yLabel('Test'),
- within(instance).queryByLabelText('button'),
- within(instance).queryByA11yHint('Test'),
- within(instance).queryByHintText('button'),
- within(instance).queryByA11yRole('button'),
- within(instance).queryByRole('button'),
- within(instance).queryByA11yState({ busy: true }),
- within(instance).queryByA11yValue({ min: 10 }),
- getQueriesForElement(instance).queryByText('Test'),
- getQueriesForElement(instance).queryByDisplayValue('Test'),
- getQueriesForElement(instance).queryByPlaceholderText('Test'),
- getQueriesForElement(instance).queryByTestId('Test'),
- getQueriesForElement(instance).queryByA11yLabel('Test'),
- getQueriesForElement(instance).queryByLabelText('button'),
- getQueriesForElement(instance).queryByA11yHint('Test'),
- getQueriesForElement(instance).queryByHintText('button'),
- getQueriesForElement(instance).queryByA11yRole('button'),
- getQueriesForElement(instance).queryByRole('button'),
- getQueriesForElement(instance).queryByA11yState({ busy: true }),
- getQueriesForElement(instance).queryByA11yValue({ min: 10 }),
-];
-
-const withinQueryAll: Array = [
- within(instance).queryAllByText('Test'),
- within(instance).queryAllByDisplayValue('Test'),
- within(instance).queryAllByPlaceholderText('Test'),
- within(instance).queryAllByTestId('Test'),
- within(instance).queryAllByA11yLabel('Test'),
- within(instance).queryAllByLabelText('Test'),
- within(instance).queryAllByA11yHint('Test'),
- within(instance).queryAllByHintText('Test'),
- within(instance).queryAllByA11yRole('button'),
- within(instance).queryAllByRole('button'),
- within(instance).queryAllByA11yState({ busy: true }),
- within(instance).queryAllByA11yValue({ min: 10 }),
- getQueriesForElement(instance).queryAllByText('Test'),
- getQueriesForElement(instance).queryAllByDisplayValue('Test'),
- getQueriesForElement(instance).queryAllByPlaceholderText('Test'),
- getQueriesForElement(instance).queryAllByTestId('Test'),
- getQueriesForElement(instance).queryAllByA11yLabel('Test'),
- getQueriesForElement(instance).queryAllByLabelText('Test'),
- getQueriesForElement(instance).queryAllByA11yHint('Test'),
- getQueriesForElement(instance).queryAllByHintText('Test'),
- getQueriesForElement(instance).queryAllByA11yRole('button'),
- getQueriesForElement(instance).queryAllByRole('button'),
- getQueriesForElement(instance).queryAllByA11yState({ busy: true }),
- getQueriesForElement(instance).queryAllByA11yValue({ min: 10 }),
-];
-
-const withinFind: Promise[] = [
- within(instance).findByText('Test'),
- within(instance).findByDisplayValue('Test'),
- within(instance).findByPlaceholderText('Test'),
- within(instance).findByTestId('Test'),
- within(instance).findByA11yLabel('Test'),
- within(instance).findByLabelText('Test'),
- within(instance).findByA11yHint('Test'),
- within(instance).findByHintText('Test'),
- within(instance).findByA11yRole('button'),
- within(instance).findByRole('button'),
- within(instance).findByA11yState({ busy: true }),
- within(instance).findByA11yValue({ min: 10 }),
- getQueriesForElement(instance).findByText('Test'),
- getQueriesForElement(instance).findByDisplayValue('Test'),
- getQueriesForElement(instance).findByPlaceholderText('Test'),
- getQueriesForElement(instance).findByTestId('Test'),
- getQueriesForElement(instance).findByA11yLabel('Test'),
- getQueriesForElement(instance).findByLabelText('Test'),
- getQueriesForElement(instance).findByA11yHint('Test'),
- getQueriesForElement(instance).findByHintText('Test'),
- getQueriesForElement(instance).findByA11yRole('button'),
- getQueriesForElement(instance).findByRole('button'),
- getQueriesForElement(instance).findByA11yState({ busy: true }),
- getQueriesForElement(instance).findByA11yValue({ min: 10 }),
-];
-
-const withinFindAll: Promise[] = [
- within(instance).findAllByText('Test'),
- within(instance).findAllByDisplayValue('Test'),
- within(instance).findAllByPlaceholderText('Test'),
- within(instance).findAllByTestId('Test'),
- within(instance).findAllByA11yLabel('Test'),
- within(instance).findAllByLabelText('Test'),
- within(instance).findAllByA11yHint('Test'),
- within(instance).findAllByHintText('Test'),
- within(instance).findAllByA11yRole('button'),
- within(instance).findAllByRole('button'),
- within(instance).findAllByA11yState({ busy: true }),
- within(instance).findAllByA11yValue({ min: 10 }),
- getQueriesForElement(instance).findAllByText('Test'),
- getQueriesForElement(instance).findAllByDisplayValue('Test'),
- getQueriesForElement(instance).findAllByPlaceholderText('Test'),
- getQueriesForElement(instance).findAllByTestId('Test'),
- getQueriesForElement(instance).findAllByA11yLabel('Test'),
- getQueriesForElement(instance).findAllByLabelText('Test'),
- getQueriesForElement(instance).findAllByA11yHint('Test'),
- getQueriesForElement(instance).findAllByHintText('Test'),
- getQueriesForElement(instance).findAllByA11yRole('button'),
- getQueriesForElement(instance).findAllByRole('button'),
- getQueriesForElement(instance).findAllByA11yState({ busy: true }),
- getQueriesForElement(instance).findAllByA11yValue({ min: 10 }),
-];
-
-// TextMatch
-const normalizer = getDefaultNormalizer({
- trim: false,
- collapseWhitespace: true,
-});
-tree.getByText('text', { exact: false, normalizer });
-tree.getByPlaceholderText('text', { exact: false, normalizer });
-tree.getByDisplayValue('text', { exact: true, normalizer });
-tree.getByTestId('text', { exact: false, normalizer });
diff --git a/typings/index.d.ts b/typings/index.d.ts
deleted file mode 100644
index 89ecc59d7..000000000
--- a/typings/index.d.ts
+++ /dev/null
@@ -1,433 +0,0 @@
-import * as React from 'react';
-import {
- AccessibilityState,
- // @ts-ignore AccessibilityStates was deprecated in RN0.62 https://reactnative.dev/blog/2020/03/26/version-0.62#breaking-changes
- AccessibilityStates,
- AccessibilityRole,
-} from 'react-native';
-import { ReactTestInstance, ReactTestRendererJSON } from 'react-test-renderer';
-
-type GetReturn = ReactTestInstance;
-type GetAllReturn = Array;
-type QueryReturn = ReactTestInstance | null;
-type QueryAllReturn = Array | [];
-type FindReturn = Promise;
-type FindAllReturn = Promise;
-
-type TextMatch = string | RegExp;
-
-interface GetByAPI {
- getByText: (text: TextMatch, options?: TextMatchOptions) => ReactTestInstance;
- getByPlaceholderText: (
- placeholder: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance;
- getByDisplayValue: (
- value: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance;
- getByTestId: (
- testID: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance;
- getAllByTestId: (
- testID: TextMatch,
- options?: TextMatchOptions
- ) => Array;
- getAllByText: (
- text: TextMatch,
- options?: TextMatchOptions
- ) => Array;
- getAllByPlaceholderText: (
- placeholder: TextMatch,
- options?: TextMatchOptions
- ) => Array;
- getAllByDisplayValue: (
- value: TextMatch,
- options?: TextMatchOptions
- ) => Array;
-
- // Unsafe aliases
- UNSAFE_getByType: (type: React.ComponentType
) => ReactTestInstance;
- UNSAFE_getAllByType:
(
- type: React.ComponentType
- ) => Array;
- UNSAFE_getByProps: (props: Record) => ReactTestInstance;
- UNSAFE_getAllByProps: (
- props: Record
- ) => Array;
-
- // 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: (type: React.ComponentType
) => ReactTestInstance;
- /**
- * @deprecated This function has been renamed to `UNSAFE_getByProps`.
- */
- getByProps: (props: Record) => ReactTestInstance;
- /**
- * @deprecated This function has been removed. Please use other queries.
- */
- getAllByName: (name: React.ReactType | string) => Array;
- /**
- * @deprecated This function has been renamed to `UNSAFE_getAllByType`.
- */
- getAllByType: (type: React.ComponentType
) => Array;
- /**
- * @deprecated This function has been renamed to `UNSAFE_getAllByProps`.
- */
- getAllByProps: (props: Record) => Array;
-}
-
-interface QueryByAPI {
- queryByText: (
- name: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance | null;
- queryByPlaceholderText: (
- placeholder: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance | null;
- queryByDisplayValue: (
- value: TextMatch,
- options?: TextMatchOptions
- ) => ReactTestInstance | null;
- queryByTestId: (testID: TextMatch) => ReactTestInstance | null;
- queryAllByTestId: (testID: TextMatch) => Array | [];
- queryAllByText: (
- text: TextMatch,
- options?: TextMatchOptions
- ) => Array | [];
- queryAllByPlaceholderText: (
- placeholder: TextMatch,
- options?: TextMatchOptions
- ) => Array | [];
- queryAllByDisplayValue: (
- value: TextMatch,
- options?: TextMatchOptions
- ) => Array | [];
-
- // Unsafe aliases
- UNSAFE_queryByType: (
- type: React.ComponentType
- ) => ReactTestInstance | null;
- UNSAFE_queryAllByType:
(
- type: React.ComponentType
- ) => Array | [];
- UNSAFE_queryByProps: (props: Record) => ReactTestInstance | null;
- UNSAFE_queryAllByProps: (
- props: Record
- ) => Array | [];
-
- // 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: (type: React.ComponentType
) => ReactTestInstance | null;
- /**
- * @deprecated This function has been renamed to `UNSAFE_queryByProps`.
- */
- queryByProps: (props: Record) => ReactTestInstance | null;
- /**
- * @deprecated This function has been removed. Please use other queries.
- */
- queryAllByName: (
- name: React.ReactType | string
- ) => Array | [];
- /**
- * @deprecated This function has been renamed to `UNSAFE_queryAllByType`.
- */
- queryAllByType: (
- type: React.ComponentType
- ) => Array | [];
- /**
- * @deprecated This function has been renamed to `UNSAFE_queryAllByProps`.
- */
- queryAllByProps: (
- props: Record
- ) => Array | [];
-}
-
-interface FindByAPI {
- findByText: (
- text: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByPlaceholderText: (
- placeholder: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByDisplayValue: (
- value: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByTestId: (
- testID: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByText: (
- text: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByPlaceholderText: (
- placeholder: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByDisplayValue: (
- value: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByTestId: (
- testID: TextMatch,
- queryOptions?: TextMatchOptions,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-}
-
-// Not yet available in DefinitelyTyped
-export type A11yValue = {
- min?: number;
- max?: number;
- now?: number;
- text?: string;
-};
-
-type A11yAPI = {
- // Label
- getByA11yLabel: (matcher: TextMatch) => GetReturn;
- getByLabelText: (matcher: TextMatch) => GetReturn;
- getAllByA11yLabel: (matcher: TextMatch) => GetAllReturn;
- getAllByLabelText: (matcher: TextMatch) => GetAllReturn;
- queryByA11yLabel: (matcher: TextMatch) => QueryReturn;
- queryByLabelText: (matcher: TextMatch) => QueryReturn;
- queryAllByA11yLabel: (matcher: TextMatch) => QueryAllReturn;
- queryAllByLabelText: (matcher: TextMatch) => QueryAllReturn;
- findByA11yLabel: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByLabelText: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByA11yLabel: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByLabelText: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-
- // Hint
- getByA11yHint: (matcher: TextMatch) => GetReturn;
- getByHintText: (matcher: TextMatch) => GetReturn;
- getAllByA11yHint: (matcher: TextMatch) => GetAllReturn;
- getAllByHintText: (matcher: TextMatch) => GetAllReturn;
- queryByA11yHint: (matcher: TextMatch) => QueryReturn;
- queryByHintText: (matcher: TextMatch) => QueryReturn;
- queryAllByA11yHint: (matcher: TextMatch) => QueryAllReturn;
- queryAllByHintText: (matcher: TextMatch) => QueryAllReturn;
- findByA11yHint: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByHintText: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByA11yHint: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByHintText: (
- matcher: TextMatch,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-
- // Role
- getByA11yRole: (matcher: AccessibilityRole | RegExp) => GetReturn;
- getByRole: (matcher: AccessibilityRole | RegExp) => GetReturn;
- getAllByA11yRole: (matcher: AccessibilityRole | RegExp) => GetAllReturn;
- getAllByRole: (matcher: AccessibilityRole | RegExp) => GetAllReturn;
- queryByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryReturn;
- queryByRole: (matcher: AccessibilityRole | RegExp) => QueryReturn;
- queryAllByA11yRole: (matcher: AccessibilityRole | RegExp) => QueryAllReturn;
- queryAllByRole: (matcher: AccessibilityRole | RegExp) => QueryAllReturn;
- findByA11yRole: (
- matcher: AccessibilityRole | RegExp,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findByRole: (
- matcher: AccessibilityRole | RegExp,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByA11yRole: (
- matcher: AccessibilityRole | RegExp,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
- findAllByRole: (
- matcher: AccessibilityRole | RegExp,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-
- // States
- getByA11yStates: (
- matcher: AccessibilityStates | Array
- ) => GetReturn;
- getAllByA11yStates: (
- matcher: AccessibilityStates | Array
- ) => GetAllReturn;
- queryByA11yStates: (
- matcher: AccessibilityStates | Array
- ) => QueryReturn;
- queryAllByA11yStates: (
- matcher: AccessibilityStates | Array
- ) => QueryAllReturn;
-
- // State
- getByA11yState: (matcher: AccessibilityState) => GetReturn;
- getAllByA11yState: (matcher: AccessibilityState) => GetAllReturn;
- queryByA11yState: (matcher: AccessibilityState) => QueryReturn;
- queryAllByA11yState: (matcher: AccessibilityState) => QueryAllReturn;
- findByA11yState: (
- matcher: AccessibilityState,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByA11yState: (
- matcher: AccessibilityState,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-
- // Value
- getByA11yValue: (matcher: A11yValue) => GetReturn;
- getAllByA11yValue: (matcher: A11yValue) => GetAllReturn;
- queryByA11yValue: (matcher: A11yValue) => QueryReturn;
- queryAllByA11yValue: (matcher: A11yValue) => QueryAllReturn;
- findByA11yValue: (
- matcher: A11yValue,
- waitForOptions?: WaitForOptions
- ) => FindReturn;
- findAllByA11yValue: (
- matcher: A11yValue,
- waitForOptions?: WaitForOptions
- ) => FindAllReturn;
-};
-
-export interface Thenable {
- then: (resolve: () => any, reject?: () => any) => any;
-}
-
-export interface RenderOptions {
- wrapper?: React.ComponentType;
- createNodeMock?: (element: React.ReactElement) => any;
-}
-
-type Debug = {
- (message?: string): void;
- shallow: (message?: string) => void;
-};
-
-type Queries = GetByAPI & QueryByAPI & FindByAPI & A11yAPI;
-
-export interface RenderAPI extends Queries {
- update(nextElement: React.ReactElement): void;
- rerender(nextElement: React.ReactElement): void;
- unmount(nextElement?: React.ReactElement): void;
- toJSON(): ReactTestRendererJSON[] | ReactTestRendererJSON | null;
- debug: Debug;
- container: ReactTestInstance;
-}
-
-export type FireEventFunction = (
- element: ReactTestInstance,
- eventName: string,
- ...data: Array
-) => any;
-
-export type FireEventAPI = FireEventFunction & {
- press: (element: ReactTestInstance, ...data: Array) => any;
- changeText: (element: ReactTestInstance, ...data: Array) => any;
- scroll: (element: ReactTestInstance, ...data: Array) => any;
-};
-
-export declare const render: (
- component: React.ReactElement,
- options?: RenderOptions
-) => RenderAPI;
-
-export declare const cleanup: () => void;
-export declare const fireEvent: FireEventAPI;
-
-type NormalizerFn = (textToNormalize: string) => string;
-type NormalizerConfig = {
- trim?: boolean;
- collapseWhitespace?: boolean;
-};
-type TextMatchOptions = {
- exact?: boolean;
- normalizer?: NormalizerFn;
-};
-
-type WaitForOptions = {
- timeout?: number;
- interval?: number;
- onTimeout?: (error: Error) => Error;
-};
-
-export type WaitForFunction = (
- expectation: () => T,
- options?: WaitForOptions
-) => Promise;
-
-export declare const waitFor: WaitForFunction;
-
-export type WaitForElementToBeRemovedFunction = (
- expectation: () => T,
- options?: WaitForOptions
-) => Promise;
-
-export declare const waitForElementToBeRemoved: WaitForElementToBeRemovedFunction;
-
-export declare const act: (callback: () => void) => Thenable;
-export declare const within: (instance: ReactTestInstance) => Queries;
-export declare const getQueriesForElement: (
- instance: ReactTestInstance
-) => Queries;
-
-export declare const getDefaultNormalizer: (
- normalizerConfig?: NormalizerConfig
-) => NormalizerFn;
-
-/**
- * @deprecated This function has been removed. Please use `waitFor` function.
- */
-export declare const waitForElement: WaitForFunction;
-
-/**
- * @deprecated This function has been deprecated and will be removed in the next release.
- */
-export declare const flushMicrotasksQueue: () => Promise;
-
-/**
- * @deprecated This function has been removed.
- */
-export declare const shallow: (
- instance: ReactTestInstance | React.ReactElement
-) => { output: React.ReactElement
};
diff --git a/typings/index.flow.js b/typings/index.flow.js
new file mode 100644
index 000000000..4c550cff7
--- /dev/null
+++ b/typings/index.flow.js
@@ -0,0 +1,366 @@
+// @flow
+import * as React from 'react';
+
+type GetReturn = ReactTestInstance;
+type GetAllReturn = Array;
+type QueryReturn = ReactTestInstance | null;
+type QueryAllReturn = Array | [];
+type FindReturn = Promise