Skip to content

Commit 6dc2734

Browse files
authored
Codemod tests to it.experimental (#17243)
`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.
1 parent a1ff9fd commit 6dc2734

10 files changed

+1005
-1008
lines changed

packages/react-dom/src/__tests__/ReactDOMFiberAsync-test.internal.js

Lines changed: 295 additions & 284 deletions
Large diffs are not rendered by default.

packages/react-dom/src/__tests__/ReactDOMHooks-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ describe('ReactDOMHooks', () => {
105105
expect(labelRef.current.innerHTML).toBe('abc');
106106
});
107107

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

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

141142
expect(labelRef.current.innerHTML).toBe('abc');
142-
});
143-
}
143+
},
144+
);
144145
});

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,9 @@ describe('ReactDOMServerHydration', () => {
500500
expect(element.textContent).toBe('Hello world');
501501
});
502502

503-
if (__EXPERIMENTAL__) {
504-
it('does not re-enter hydration after committing the first one', () => {
503+
it.experimental(
504+
'does not re-enter hydration after committing the first one',
505+
() => {
505506
let finalHTML = ReactDOMServer.renderToString(<div />);
506507
let container = document.createElement('div');
507508
container.innerHTML = finalHTML;
@@ -514,8 +515,8 @@ describe('ReactDOMServerHydration', () => {
514515
// warnings.
515516
root.render(<div />);
516517
Scheduler.unstable_flushAll();
517-
});
518-
}
518+
},
519+
);
519520

520521
it('Suspense + hydration in legacy mode', () => {
521522
const element = document.createElement('div');

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,27 @@ describe('ReactTestUtils.act()', () => {
125125
]);
126126
});
127127

128-
if (__EXPERIMENTAL__) {
129-
it('warns in blocking mode', () => {
130-
expect(() => {
131-
const root = ReactDOM.createBlockingRoot(
132-
document.createElement('div'),
133-
);
134-
root.render(<App />);
135-
Scheduler.unstable_flushAll();
136-
}).toWarnDev([
137-
'An update to App ran an effect, but was not wrapped in act(...)',
138-
'An update to App ran an effect, but was not wrapped in act(...)',
139-
]);
140-
});
128+
it.experimental('warns in blocking mode', () => {
129+
expect(() => {
130+
const root = ReactDOM.createBlockingRoot(document.createElement('div'));
131+
root.render(<App />);
132+
Scheduler.unstable_flushAll();
133+
}).toWarnDev([
134+
'An update to App ran an effect, but was not wrapped in act(...)',
135+
'An update to App ran an effect, but was not wrapped in act(...)',
136+
]);
137+
});
141138

142-
it('warns in concurrent mode', () => {
143-
expect(() => {
144-
const root = ReactDOM.createRoot(document.createElement('div'));
145-
root.render(<App />);
146-
Scheduler.unstable_flushAll();
147-
}).toWarnDev([
148-
'An update to App ran an effect, but was not wrapped in act(...)',
149-
'An update to App ran an effect, but was not wrapped in act(...)',
150-
]);
151-
});
152-
}
139+
it.experimental('warns in concurrent mode', () => {
140+
expect(() => {
141+
const root = ReactDOM.createRoot(document.createElement('div'));
142+
root.render(<App />);
143+
Scheduler.unstable_flushAll();
144+
}).toWarnDev([
145+
'An update to App ran an effect, but was not wrapped in act(...)',
146+
'An update to App ran an effect, but was not wrapped in act(...)',
147+
]);
148+
});
153149
});
154150
});
155151

packages/react-dom/src/__tests__/ReactUnmockedSchedulerWarning-test.js

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,30 @@ it('does not warn when rendering in legacy mode', () => {
2727
}).toWarnDev([]);
2828
});
2929

30-
if (__EXPERIMENTAL__) {
31-
it('should warn when rendering in concurrent mode', () => {
32-
expect(() => {
33-
ReactDOM.createRoot(document.createElement('div')).render(<App />);
34-
}).toWarnDev(
35-
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
36-
'to guarantee consistent behaviour across tests and browsers.',
37-
{withoutStack: true},
38-
);
39-
// does not warn twice
40-
expect(() => {
41-
ReactDOM.createRoot(document.createElement('div')).render(<App />);
42-
}).toWarnDev([]);
43-
});
30+
it.experimental('should warn when rendering in concurrent mode', () => {
31+
expect(() => {
32+
ReactDOM.createRoot(document.createElement('div')).render(<App />);
33+
}).toWarnDev(
34+
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
35+
'to guarantee consistent behaviour across tests and browsers.',
36+
{withoutStack: true},
37+
);
38+
// does not warn twice
39+
expect(() => {
40+
ReactDOM.createRoot(document.createElement('div')).render(<App />);
41+
}).toWarnDev([]);
42+
});
4443

45-
it('should warn when rendering in blocking mode', () => {
46-
expect(() => {
47-
ReactDOM.createBlockingRoot(document.createElement('div')).render(
48-
<App />,
49-
);
50-
}).toWarnDev(
51-
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
52-
'to guarantee consistent behaviour across tests and browsers.',
53-
{withoutStack: true},
54-
);
55-
// does not warn twice
56-
expect(() => {
57-
ReactDOM.createBlockingRoot(document.createElement('div')).render(
58-
<App />,
59-
);
60-
}).toWarnDev([]);
61-
});
62-
}
44+
it.experimental('should warn when rendering in blocking mode', () => {
45+
expect(() => {
46+
ReactDOM.createBlockingRoot(document.createElement('div')).render(<App />);
47+
}).toWarnDev(
48+
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
49+
'to guarantee consistent behaviour across tests and browsers.',
50+
{withoutStack: true},
51+
);
52+
// does not warn twice
53+
expect(() => {
54+
ReactDOM.createBlockingRoot(document.createElement('div')).render(<App />);
55+
}).toWarnDev([]);
56+
});

0 commit comments

Comments
 (0)