Skip to content

Commit b9faa3b

Browse files
author
Sunil Pai
authored
[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).
1 parent 66a4742 commit b9faa3b

File tree

2 files changed

+1
-43
lines changed

2 files changed

+1
-43
lines changed

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import type {Thenable} from 'react-reconciler/src/ReactFiberWorkLoop';
87

98
import React from 'react';
109
import ReactDOM from 'react-dom';
@@ -19,7 +18,6 @@ import {
1918
import SyntheticEvent from 'events/SyntheticEvent';
2019
import invariant from 'shared/invariant';
2120
import lowPriorityWarning from 'shared/lowPriorityWarning';
22-
import warningWithoutStack from 'shared/warningWithoutStack';
2321
import {ELEMENT_NODE} from '../shared/HTMLNodeType';
2422
import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
2523
import {PLUGIN_EVENT_SYSTEM} from 'events/EventSystemFlags';
@@ -153,12 +151,6 @@ function validateClassInstance(inst, methodName) {
153151
);
154152
}
155153

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-
162154
/**
163155
* Utilities for making it easy to test React components.
164156
*
@@ -395,25 +387,7 @@ const ReactTestUtils = {
395387
Simulate: null,
396388
SimulateNative: {},
397389

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,
417391
};
418392

419393
/**

packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.internal.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,20 +1022,4 @@ describe('ReactTestRenderer', () => {
10221022
expect(Scheduler).toFlushWithoutYielding();
10231023
ReactTestRenderer.create(<App />);
10241024
});
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-
});
10411025
});

0 commit comments

Comments
 (0)