feat: Add Typescript types to waitForElement (#21)

Fix types for Flow too
This commit is contained in:
Kacper Wiszczuk
2018-10-10 21:45:32 +02:00
committed by Michał Pierzchała
parent d5219d2e93
commit 480dd28cbc
4 changed files with 25 additions and 4 deletions
+15 -1
View File
@@ -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);
+7
View File
@@ -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;