forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
warn when using the wrong act() around create/updates
via facebook#15319 This solves 2 specific problems - - using the 'wrong' act() doesn't silence the warning - using the wrong act logs a warning It does this by using an empty object on the reconciler as the identity of ReactShouldWarnActingUpdates.current. We also add this check when calling createContainer() to catch the common failure of this happening right in the beginning.
- Loading branch information
Sunil Pai
committed
Apr 12, 2019
1 parent
a09bd0f
commit 6aac3a2
Showing
17 changed files
with
182 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>sanity test for ReactTestUtils.act</title> | ||
</head> | ||
<body> | ||
this page tests whether act runs properly in a browser. | ||
<br/> | ||
your console should say "5" | ||
<script src='react.development.js'></script> | ||
<script src='react-dom.development.js'></script> | ||
<script src='react-dom-test-utils.development.js'></script> | ||
<script> | ||
async function run(){ | ||
// from ReactTestUtilsAct-test.js | ||
<head> | ||
<title>sanity test for ReactTestUtils.act</title> | ||
</head> | ||
<body> | ||
this page tests whether act runs properly in a browser. | ||
<br /> | ||
your console should say "5", and a warning about not using the right act() | ||
<script src="react.development.js"></script> | ||
<script src="react-dom.development.js"></script> | ||
<script src="react-dom-test-utils.development.js"></script> | ||
<script src="scheduler.development.js"></script> | ||
<script src="react-test-renderer.development.js"></script> | ||
<script> | ||
window.jest = {}; // to enable warnings | ||
function App() { | ||
let [state, setState] = React.useState(0); | ||
async function ticker() { | ||
await null; | ||
setState(x => x + 1); | ||
} | ||
React.useEffect( | ||
() => { | ||
ticker(); | ||
}, | ||
[Math.min(state, 4)], | ||
); | ||
React.useEffect(() => { | ||
ticker(); | ||
}, [Math.min(state, 4)]); | ||
return state; | ||
} | ||
const el = document.createElement('div'); | ||
await ReactTestUtils.act(async () => { | ||
ReactDOM.render(React.createElement(App), el); | ||
}); | ||
// all 5 ticks present and accounted for | ||
console.log(el.innerHTML); | ||
} | ||
run(); | ||
|
||
</script> | ||
</body> | ||
|
||
function sleep(period){ | ||
return new Promise(resolve => setTimeout(resolve, period)) | ||
} | ||
|
||
async function testDOMAsynAct() { | ||
// from ReactTestUtilsAct-test.js | ||
|
||
const el = document.createElement("div"); | ||
await ReactTestUtils.act(async () => { | ||
ReactDOM.render(React.createElement(App), el); | ||
}); | ||
// all 5 ticks present and accounted for | ||
console.log(el.innerHTML); | ||
} | ||
|
||
async function testMixRenderers() { | ||
await ReactTestUtils.act(async () => { | ||
ReactTestRenderer.create(React.createElement(App)); | ||
}); | ||
} | ||
|
||
async function run() { | ||
await testDOMAsynAct(); | ||
await testMixRenderers(); | ||
} | ||
|
||
run(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.