From 4b81edcaf875cc41574264544417c7d6bbb04efd Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Mon, 19 Aug 2019 22:02:30 +0200 Subject: [PATCH] feat(react-dom): Add async act (#37554) * feat(react-dom): Add async act typings * Update version * Normalize typing with react-test-renderer --- types/react-dom/index.d.ts | 2 +- types/react-dom/react-dom-tests.tsx | 5 ++--- types/react-dom/test-utils/index.d.ts | 4 +++- types/react-dom/tslint.json | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/types/react-dom/index.d.ts b/types/react-dom/index.d.ts index 1af1647a3b..7c6fd66f89 100644 --- a/types/react-dom/index.d.ts +++ b/types/react-dom/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for React (react-dom) 16.8 +// Type definitions for React (react-dom) 16.9 // Project: http://facebook.github.io/react/ // Definitions by: Asana // AssureSign diff --git a/types/react-dom/react-dom-tests.tsx b/types/react-dom/react-dom-tests.tsx index 20bfda53ea..72f5763fc9 100644 --- a/types/react-dom/react-dom-tests.tsx +++ b/types/react-dom/react-dom-tests.tsx @@ -185,9 +185,8 @@ describe('React dom test utils', () => { it('accepts a sync callback that is void', () => { ReactTestUtils.act(() => {}); }); - it('rejects an async callback even if void', () => { - // $ExpectError - ReactTestUtils.act(async () => {}); + it('accepts an async callback that is void', async () => { + await ReactTestUtils.act(async () => {}); }); it('rejects a callback that returns null', () => { // $ExpectError diff --git a/types/react-dom/test-utils/index.d.ts b/types/react-dom/test-utils/index.d.ts index 23a10bc79d..39fd1f5e36 100644 --- a/types/react-dom/test-utils/index.d.ts +++ b/types/react-dom/test-utils/index.d.ts @@ -291,8 +291,10 @@ export function createRenderer(): ShallowRenderer; * @see https://reactjs.org/blog/2019/02/06/react-v16.8.0.html#testing-hooks */ // the "void | undefined" is here to forbid any sneaky "Promise" returns. -// the actual return value is always a "DebugPromiseLike". export function act(callback: () => void | undefined): DebugPromiseLike; +// the "void | undefined" is here to forbid any sneaky return values +// tslint:disable-next-line: void-return +export function act(callback: () => Promise): Promise; // Intentionally doesn't extend PromiseLike. // Ideally this should be as hard to accidentally use as possible. diff --git a/types/react-dom/tslint.json b/types/react-dom/tslint.json index 3dc65c7465..0a88bba28a 100644 --- a/types/react-dom/tslint.json +++ b/types/react-dom/tslint.json @@ -7,4 +7,4 @@ "no-unnecessary-generics": false, "no-unnecessary-type-assertion": false } -} \ No newline at end of file +}