Skip to content

Commit

Permalink
[act] remove obsolete container element
Browse files Browse the repository at this point in the history
In a previous version of `act()`, we used a dummy dom element to flush effects and such. This doesn't need to exist anymore. The warning itself is still useful, so we'll keep it. Updated the test.
  • Loading branch information
threepointone committed Aug 7, 2019
1 parent c4f0b93 commit 1e3aef4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ function validateClassInstance(inst, methodName) {
);
}

// a plain dom element, lazily initialized, used by act() when flushing effects
let actContainerElement = null;

// a warning for when you try to use TestUtils.act in a non-browser environment
let didWarnAboutActInNodejs = false;

Expand Down Expand Up @@ -396,21 +393,17 @@ const ReactTestUtils = {
SimulateNative: {},

act(callback: () => Thenable) {
if (actContainerElement === null) {
if (__DEV__) {
// warn if we're trying to use this in something like node (without jsdom)
if (didWarnAboutActInNodejs === false) {
didWarnAboutActInNodejs = true;
warningWithoutStack(
typeof document !== 'undefined' && document !== null,
'It looks like you called ReactTestUtils.act(...) in a non-browser environment. ' +
"If you're using TestRenderer for your tests, you should call " +
'ReactTestRenderer.act(...) instead of ReactTestUtils.act(...).',
);
}
if (__DEV__) {
// warn if we're trying to use this in something like node (without jsdom)
if (didWarnAboutActInNodejs === false) {
didWarnAboutActInNodejs = true;
warningWithoutStack(
typeof document !== 'undefined' && document !== null,
'It looks like you called ReactTestUtils.act(...) in a non-browser environment. ' +
"If you're using TestRenderer for your tests, you should call " +
'ReactTestRenderer.act(...) instead of ReactTestUtils.act(...).',
);
}
// now make the stub element
actContainerElement = document.createElement('div');
}
return act(callback);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,13 +1024,13 @@ describe('ReactTestRenderer', () => {
});

// we run this test here because we need a dom-less scope
it('warns and throws if you use TestUtils.act instead of TestRenderer.act in node', () => {
it('warns if you use TestUtils.act instead of TestRenderer.act in node', () => {
// we warn when you try to load 2 renderers in the same 'scope'
// so as suggested, we call resetModules() to carry on with the test
jest.resetModules();
const {act} = require('react-dom/test-utils');
expect(() => {
expect(() => act(() => {})).toThrow('document is not defined');
act(() => {});
}).toWarnDev(
[
'It looks like you called ReactTestUtils.act(...) in a non-browser environment',
Expand Down

0 comments on commit 1e3aef4

Please sign in to comment.