mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
feat: wrap render with act() for better React Hooks support (#122)
This commit is contained in:
committed by
Michał Pierzchała
parent
747e864369
commit
11489b0e5e
@@ -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 />);
|
||||
});
|
||||
|
||||
Vendored
+5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user