main
html 44 lines 1.28 KB
Raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>sanity test for ReactTestUtils.act</title>
5 </head>
6 <body>
7 this page tests whether act runs properly in a browser.
8 <br />
9 your console should say "5"
10 <script src="scheduler-unstable_mock.development.js"></script>
11 <script src="react.development.js"></script>
12 <script type="text/javascript">
13 window.React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE.Scheduler =
14 window.SchedulerMock;
15 </script>
16 <script src="react-dom.development.js"></script>
17 <script src="react-dom-test-utils.development.js"></script>
18 <script>
19 // from ReactTestUtilsAct-test.js
20 function App() {
21 let [state, setState] = React.useState(0);
22 async function ticker() {
23 await null;
24 setState(x => x + 1);
25 }
26 React.useEffect(() => {
27 ticker();
28 }, [Math.min(state, 4)]);
29 return state;
30 }
31
32 async function testAsyncAct() {
33 const el = document.createElement("div");
34 await ReactTestUtils.act(async () => {
35 ReactDOM.render(React.createElement(App), el);
36 });
37 // all 5 ticks present and accounted for
38 console.log(el.innerHTML);
39 }
40
41 testAsyncAct();
42 </script>
43 </body>
44 </html>