Skip to content

Commit a978e52

Browse files
authored
fix: corrects the type for act
Corrects for the addition of returned values from the act function: facebook/react#21759
1 parent 4ff2a27 commit a978e52

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

types/react-dom/test-utils/index.d.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,16 @@ export function createRenderer(): ShallowRenderer;
281281
* Wrap any code rendering and triggering updates to your components into `act()` calls.
282282
*
283283
* Ensures that the behavior in your tests matches what happens in the browser
284-
* more closely by executing pending `useEffect`s before returning. This also
285-
* reduces the amount of re-renders done.
284+
* more closely by executing pending `useEffect`s before returning.
285+
*
286+
* All `useEffect`s scheduled by the actions within the callback will be condensed into
287+
* a single action, with only the latest values returned, to improve the efficiency of the test.
286288
*
287-
* @param callback A synchronous, void callback that will execute as a single, complete React commit.
289+
* @param callback A synchronous or asyncronous callback that will execute as a single, complete React commit.
288290
*
289291
* @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks
290292
*/
291-
// NOTES
292-
// - the order of these signatures matters - typescript will check the signatures in source order.
293-
// If the `() => VoidOrUndefinedOnly` signature is first, it'll erroneously match a Promise returning function for users with
294-
// `strictNullChecks: false`.
295-
// - VoidOrUndefinedOnly is there to forbid any non-void return values for users with `strictNullChecks: true`
296-
declare const UNDEFINED_VOID_ONLY: unique symbol;
297-
// tslint:disable-next-line: void-return
298-
type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
299-
export function act(callback: () => Promise<void>): Promise<undefined>;
300-
export function act(callback: () => VoidOrUndefinedOnly): void;
293+
export function act<T>(callback: () => Promise<T> | T): Promise<T>;
301294

302295
// Intentionally doesn't extend PromiseLike<never>.
303296
// Ideally this should be as hard to accidentally use as possible.

0 commit comments

Comments
 (0)