Skip to content

Commit

Permalink
Codemod tests to it.experimental (#17243)
Browse files Browse the repository at this point in the history
`it.experimental` marks that a test only works in Experimental builds.

It also asserts that a test does *not* work in the stable builds. The
main benefit is that we're less likely to accidentally expose an
experimental API before we intend. It also forces us to un- mark an
experimental test once it become stable.
  • Loading branch information
acdlite authored Nov 1, 2019
1 parent a1ff9fd commit 6dc2734
Show file tree
Hide file tree
Showing 10 changed files with 1,005 additions and 1,008 deletions.
579 changes: 295 additions & 284 deletions packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.internal.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ describe('ReactDOMHooks', () => {
expect(labelRef.current.innerHTML).toBe('abc');
});

if (__EXPERIMENTAL__) {
it('should not bail out when an update is scheduled from within an event handler in Concurrent Mode', () => {
it.experimental(
'should not bail out when an update is scheduled from within an event handler in Concurrent Mode',
() => {
const {createRef, useCallback, useState} = React;

const Example = ({inputRef, labelRef}) => {
Expand Down Expand Up @@ -139,6 +140,6 @@ describe('ReactDOMHooks', () => {
Scheduler.unstable_flushAll();

expect(labelRef.current.innerHTML).toBe('abc');
});
}
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,9 @@ describe('ReactDOMServerHydration', () => {
expect(element.textContent).toBe('Hello world');
});

if (__EXPERIMENTAL__) {
it('does not re-enter hydration after committing the first one', () => {
it.experimental(
'does not re-enter hydration after committing the first one',
() => {
let finalHTML = ReactDOMServer.renderToString(<div />);
let container = document.createElement('div');
container.innerHTML = finalHTML;
Expand All @@ -514,8 +515,8 @@ describe('ReactDOMServerHydration', () => {
// warnings.
root.render(<div />);
Scheduler.unstable_flushAll();
});
}
},
);

it('Suspense + hydration in legacy mode', () => {
const element = document.createElement('div');
Expand Down
44 changes: 20 additions & 24 deletions packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,27 @@ describe('ReactTestUtils.act()', () => {
]);
});

if (__EXPERIMENTAL__) {
it('warns in blocking mode', () => {
expect(() => {
const root = ReactDOM.createBlockingRoot(
document.createElement('div'),
);
root.render(<App />);
Scheduler.unstable_flushAll();
}).toWarnDev([
'An update to App ran an effect, but was not wrapped in act(...)',
'An update to App ran an effect, but was not wrapped in act(...)',
]);
});
it.experimental('warns in blocking mode', () => {
expect(() => {
const root = ReactDOM.createBlockingRoot(document.createElement('div'));
root.render(<App />);
Scheduler.unstable_flushAll();
}).toWarnDev([
'An update to App ran an effect, but was not wrapped in act(...)',
'An update to App ran an effect, but was not wrapped in act(...)',
]);
});

it('warns in concurrent mode', () => {
expect(() => {
const root = ReactDOM.createRoot(document.createElement('div'));
root.render(<App />);
Scheduler.unstable_flushAll();
}).toWarnDev([
'An update to App ran an effect, but was not wrapped in act(...)',
'An update to App ran an effect, but was not wrapped in act(...)',
]);
});
}
it.experimental('warns in concurrent mode', () => {
expect(() => {
const root = ReactDOM.createRoot(document.createElement('div'));
root.render(<App />);
Scheduler.unstable_flushAll();
}).toWarnDev([
'An update to App ran an effect, but was not wrapped in act(...)',
'An update to App ran an effect, but was not wrapped in act(...)',
]);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,30 @@ it('does not warn when rendering in legacy mode', () => {
}).toWarnDev([]);
});

if (__EXPERIMENTAL__) {
it('should warn when rendering in concurrent mode', () => {
expect(() => {
ReactDOM.createRoot(document.createElement('div')).render(<App />);
}).toWarnDev(
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers.',
{withoutStack: true},
);
// does not warn twice
expect(() => {
ReactDOM.createRoot(document.createElement('div')).render(<App />);
}).toWarnDev([]);
});
it.experimental('should warn when rendering in concurrent mode', () => {
expect(() => {
ReactDOM.createRoot(document.createElement('div')).render(<App />);
}).toWarnDev(
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers.',
{withoutStack: true},
);
// does not warn twice
expect(() => {
ReactDOM.createRoot(document.createElement('div')).render(<App />);
}).toWarnDev([]);
});

it('should warn when rendering in blocking mode', () => {
expect(() => {
ReactDOM.createBlockingRoot(document.createElement('div')).render(
<App />,
);
}).toWarnDev(
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers.',
{withoutStack: true},
);
// does not warn twice
expect(() => {
ReactDOM.createBlockingRoot(document.createElement('div')).render(
<App />,
);
}).toWarnDev([]);
});
}
it.experimental('should warn when rendering in blocking mode', () => {
expect(() => {
ReactDOM.createBlockingRoot(document.createElement('div')).render(<App />);
}).toWarnDev(
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers.',
{withoutStack: true},
);
// does not warn twice
expect(() => {
ReactDOM.createBlockingRoot(document.createElement('div')).render(<App />);
}).toWarnDev([]);
});
Loading

0 comments on commit 6dc2734

Please sign in to comment.