[act] remove obsolete container element (#16312)
In a previous version of act(), we used a dummy dom element to flush effects. This doesn't need to exist anymore, and this PR removes it. The warning doesn't need to be there either (React will fire a wrong renderer act warning if needed).
Sunil Pai committed
Aug 9, 2019 at 14:26 UTC
b9faa3b0925f9842f12150bc5b6ac4b19c31e9ed
2 files changed
+1
-43
packages/react-dom/src/test-utils/ReactTestUtils.js
+1
-27
@@ -4,7 +4,6 @@
4
* This source code is licensed under the MIT license found in the
5
* LICENSE file in the root directory of this source tree.
6
*/
7
-import type {Thenable} from 'react-reconciler/src/ReactFiberWorkLoop';
7
8
import React from 'react';
9
import ReactDOM from 'react-dom';
@@ -19,7 +18,6 @@ import {
18
import SyntheticEvent from 'events/SyntheticEvent';
19
import invariant from 'shared/invariant';
20
import lowPriorityWarning from 'shared/lowPriorityWarning';
22
-import warningWithoutStack from 'shared/warningWithoutStack';
21
import {ELEMENT_NODE} from '../shared/HTMLNodeType';
22
import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
23
import {PLUGIN_EVENT_SYSTEM} from 'events/EventSystemFlags';
@@ -153,12 +151,6 @@ function validateClassInstance(inst, methodName) {
151
);
152
}
153
156
-// a plain dom element, lazily initialized, used by act() when flushing effects
157
-let actContainerElement = null;
158
-
159
-// a warning for when you try to use TestUtils.act in a non-browser environment
160
-let didWarnAboutActInNodejs = false;
161
-
154
/**
155
* Utilities for making it easy to test React components.
156
*
@@ -395,25 +387,7 @@ const ReactTestUtils = {
387
Simulate: null,
388
SimulateNative: {},
389
398
- act(callback: () => Thenable) {
399
- if (actContainerElement === null) {
400
- if (__DEV__) {
401
- // warn if we're trying to use this in something like node (without jsdom)
402
- if (didWarnAboutActInNodejs === false) {
403
- didWarnAboutActInNodejs = true;
404
- warningWithoutStack(
405
- typeof document !== 'undefined' && document !== null,
406
- 'It looks like you called ReactTestUtils.act(...) in a non-browser environment. ' +
407
- "If you're using TestRenderer for your tests, you should call " +
408
- 'ReactTestRenderer.act(...) instead of ReactTestUtils.act(...).',
409
- );
410
- }
411
- }
412
- // now make the stub element
413
- actContainerElement = document.createElement('div');
414
- }
415
- return act(callback);
416
- },
390
+ act,
391
};
392
393
/**
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js
-16
@@ -1022,20 +1022,4 @@ describe('ReactTestRenderer', () => {
1022
expect(Scheduler).toFlushWithoutYielding();
1023
ReactTestRenderer.create(<App />);
1024
});
1025
-
1026
- // we run this test here because we need a dom-less scope
1027
- it('warns and throws if you use TestUtils.act instead of TestRenderer.act in node', () => {
1028
- // we warn when you try to load 2 renderers in the same 'scope'
1029
- // so as suggested, we call resetModules() to carry on with the test
1030
- jest.resetModules();
1031
- const {act} = require('react-dom/test-utils');
1032
- expect(() => {
1033
- expect(() => act(() => {})).toThrow('document is not defined');
1034
- }).toWarnDev(
1035
- [
1036
- 'It looks like you called ReactTestUtils.act(...) in a non-browser environment',
1037
- ],
1038
- {withoutStack: 1},
1039
- );
1040
- });
1025
});