Skip to content

Commit

Permalink
feat(react-dom): Add async act (#37554)
Browse files Browse the repository at this point in the history
* feat(react-dom): Add async act typings

* Update version

* Normalize typing with react-test-renderer
  • Loading branch information
eps1lon authored and sheetalkamat committed Aug 19, 2019
1 parent f0708ac commit 4b81edc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 <https://asana.com>
// AssureSign <http://www.assuresign.com>
Expand Down
5 changes: 2 additions & 3 deletions types/react-dom/react-dom-tests.tsx
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion types/react-dom/test-utils/index.d.ts
Expand Up @@ -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<void | undefined>): Promise<undefined>;

// Intentionally doesn't extend PromiseLike<never>.
// Ideally this should be as hard to accidentally use as possible.
Expand Down
2 changes: 1 addition & 1 deletion types/react-dom/tslint.json
Expand Up @@ -7,4 +7,4 @@
"no-unnecessary-generics": false,
"no-unnecessary-type-assertion": false
}
}
}

0 comments on commit 4b81edc

Please sign in to comment.