Skip to content

[react-dom] expose TestUtils.act() #7440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/react-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ declare module 'react-dom/server' {
declare var version: string;
}

type Thenable = {
then(resolve: () => mixed, reject?: () => mixed): mixed,
};

declare module 'react-dom/test-utils' {
declare var Simulate: {
[eventName: string]: (element: Element, eventData?: Object) => void,
Expand Down Expand Up @@ -113,6 +117,7 @@ declare module 'react-dom/test-utils' {
tree: React$Component<any, any>,
componentClass: React$ElementType,
): ?React$Component<any, any>;
declare function act<X>(callback: () => void): Thenable;
}

declare class SyntheticEvent<+T: EventTarget = EventTarget, +E: Event = Event> {
Expand Down
43 changes: 43 additions & 0 deletions tests/react/react.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- react.exp
+++ react.out
@@ -3093,11 +3093,29 @@
^^^^^^^^^^^^^

References:
- <BUILTINS>/react-dom.js:90:19
- 90| test: (child: React$Component<any, any>) => boolean,
+ <BUILTINS>/react-dom.js:94:19
+ 94| test: (child: React$Component<any, any>) => boolean,
^^^^^^^^^^^^^^^^^^^^^^^^^ [1]


+Error ---------------------------------------------------------------------------------------------- test-utils.js:57:15
+
+Cannot call `TestUtils.act` with function bound to `callback` because object literal [1] is incompatible with
+undefined [2] in the return value.
+
+ test-utils.js:57:15
+ 57| TestUtils.act(() => ({count: 123})); // error
+ ^^^^^^^^^^^^^^^^^^^^
+
+References:
+ test-utils.js:57:22
+ 57| TestUtils.act(() => ({count: 123})); // error
+ ^^^^^^^^^^^^ [1]
+ <BUILTINS>/react-dom.js:120:43
+ 120| declare function act<X>(callback: () => void): Thenable;
+ ^^^^ [2]
+
+
Error -------------------------------------------------------------------------------------------- undefined_prop.js:7:1

Cannot create `MyComponent` element because undefined [1] is incompatible with string [2] in property `title`.
@@ -4107,7 +4125,7 @@



-Found 241 errors
+Found 242 errors

Only showing the most relevant union/intersection branches.
To see all branches, re-run Flow with --show-all-branches
4 changes: 4 additions & 0 deletions tests/react/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ if (buttonEl != null) {
tree,
MyTestingComponent,
): ?React.Component<any, any>);
TestUtils.act(() => {
Math.random();
});
TestUtils.act(() => ({count: 123})); // error
24 changes: 24 additions & 0 deletions tests/react_16_3/react_16_3.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- react_16_3.exp
+++ react_16_3.out
@@ -40,8 +40,8 @@
forwardRef.js:19:32
19| const badRef = React.createRef<HTMLDivElement>();
^^^^^^^^^^^^^^ [1]
- <BUILTINS>/react-dom.js:284:22
- 284| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
+ <BUILTINS>/react-dom.js:289:22
+ 289| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
^^^^^^^^^^^^^^^^^ [2]
<BUILTINS>/react.js:240:6
240| ): {current: null | T};
@@ -71,8 +71,8 @@
forwardRef.js:23:50
23| const _g = <FancyButton foo={3} ref={(x: null | HTMLDivElement) => x} />; // Incorrect ref type
^^^^^^^^^^^^^^ [3]
- <BUILTINS>/react-dom.js:284:22
- 284| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
+ <BUILTINS>/react-dom.js:289:22
+ 289| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
^^^^^^^^^^^^^^^^^ [4]