feat: wrap render with act() for better React Hooks support (#122)

This commit is contained in:
Kacper Wiszczuk
2019-02-28 21:53:26 +01:00
committed by Michał Pierzchała
parent 747e864369
commit 11489b0e5e
11 changed files with 144 additions and 35 deletions
+5
View File
@@ -7,6 +7,7 @@ import {
flushMicrotasksQueue,
debug,
waitForElement,
act,
} from '../..';
interface HasRequiredProp {
@@ -131,3 +132,7 @@ const waitBy: Promise<ReactTestInstance> = waitForElement<ReactTestInstance>(
const waitByAll: Promise<Array<ReactTestInstance>> = waitForElement<
Array<ReactTestInstance>
>(() => tree.getAllByName('View'), 1000, 50);
act(() => {
render(<TestComponent />);
});
+5
View File
@@ -33,6 +33,10 @@ export interface QueryByAPI {
) => Array<ReactTestInstance> | [];
}
export interface Thenable {
then: (resolve: () => any, reject?: () => any) => any,
}
export interface RenderOptions {
createNodeMock: (element: React.ReactElement<any>) => any;
}
@@ -86,3 +90,4 @@ export declare const flushMicrotasksQueue: () => Promise<any>;
export declare const debug: DebugAPI;
export declare const fireEvent: FireEventAPI;
export declare const waitForElement: WaitForElementFunction;
export declare const act: (callback: () => void) => Thenable;