mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
feat: Add Typescript types to waitForElement (#21)
Fix types for Flow too
This commit is contained in:
committed by
Michał Pierzchała
parent
d5219d2e93
commit
480dd28cbc
@@ -1,6 +1,13 @@
|
||||
import * as React from 'react';
|
||||
import { ReactTestInstance } from 'react-test-renderer';
|
||||
import { render, fireEvent, shallow, flushMicrotasksQueue, debug } from '../..';
|
||||
import {
|
||||
render,
|
||||
fireEvent,
|
||||
shallow,
|
||||
flushMicrotasksQueue,
|
||||
debug,
|
||||
waitForElement,
|
||||
} from '../..';
|
||||
|
||||
const View = props => props.children;
|
||||
const Text = props => props.children;
|
||||
@@ -77,3 +84,10 @@ const waitForFlush: Promise<any> = flushMicrotasksQueue();
|
||||
|
||||
debug(<TestComponent />);
|
||||
debug(getByNameString);
|
||||
|
||||
const waitBy: Promise<ReactTestInstance> = waitForElement<ReactTestInstance>(
|
||||
() => tree.getByName('View')
|
||||
);
|
||||
const waitByAll: Promise<Array<ReactTestInstance>> = waitForElement<
|
||||
Array<ReactTestInstance>
|
||||
>(() => tree.getAllByName('View'), 1000, 50);
|
||||
|
||||
Vendored
+7
@@ -45,6 +45,12 @@ export type FireEventAPI = FireEventFunction & {
|
||||
scroll: (element: ReactTestInstance, data?: any) => any;
|
||||
};
|
||||
|
||||
export type WaitForElementFunction = <T = any>(
|
||||
expectation: () => T,
|
||||
timeout?: number,
|
||||
interval?: number
|
||||
) => Promise<T>;
|
||||
|
||||
export declare const render: (
|
||||
component: React.ReactElement<any>,
|
||||
options?: RenderOptions
|
||||
@@ -57,3 +63,4 @@ export declare const debug: (
|
||||
instance: ReactTestInstance | React.ReactElement<any>
|
||||
) => void;
|
||||
export declare const fireEvent: FireEventAPI;
|
||||
export declare const waitForElement: WaitForElementFunction;
|
||||
|
||||
Reference in New Issue
Block a user