Skip to content

Commit

Permalink
[TestUtils.act] warn when using TestUtils.act in node (#14768)
Browse files Browse the repository at this point in the history
* warn when using TestUtils.act in node

* s/warns/throws

* s/throw/warn

* consistent ellipses
  • Loading branch information
Sunil Pai authored Feb 6, 2019
1 parent c7ab86f commit 6005665
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/__tests__/ReactTestRenderer-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ describe('ReactTestRenderer', () => {
});

describe('act', () => {
it('works', () => {
it('can use .act() to batch updates and effects', () => {
function App(props) {
React.useEffect(() => {
props.callback();
Expand All @@ -1043,5 +1043,19 @@ describe('ReactTestRenderer', () => {

expect(called).toBe(true);
});
it('warns and throws 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');
}).toWarnDev(
[
'It looks like you called TestUtils.act(...) in a non-browser environment',
],
{withoutStack: 1},
);
});
});
});

0 comments on commit 6005665

Please sign in to comment.