Skip to content

Commit eb7d88f

Browse files
committed
Update warning tests
1 parent 43b7586 commit eb7d88f

File tree

3 files changed

+59
-50
lines changed

3 files changed

+59
-50
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('DOMPropertyOperations', () => {
184184
container,
185185
),
186186
).toWarnDev(
187-
'A component is changing a controlled input of type text to be uncontrolled',
187+
'A component is changing a controlled input to be uncontrolled',
188188
);
189189
if (disableInputAttributeSyncing) {
190190
expect(container.firstChild.hasAttribute('value')).toBe(false);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ describe('ReactDOMComponentTree', () => {
178178
const component = <Controlled />;
179179
const instance = ReactDOM.render(component, container);
180180
expect(() => simulateInput(instance.a, finishValue)).toWarnDev(
181-
'Warning: A component is changing an uncontrolled input of ' +
182-
'type text to be controlled. Input elements should not ' +
183-
'switch from uncontrolled to controlled (or vice versa). ' +
181+
'Warning: A component is changing an uncontrolled input to be ' +
182+
'controlled. This is likely caused by the value changing from ' +
183+
'a defined to undefined, which should not happen. ' +
184184
'Decide between using a controlled or uncontrolled input ' +
185185
'element for the lifetime of the component. More info: ' +
186186
'https://fb.me/react-controlled-components',

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

+55-46
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ describe('ReactDOMInput', () => {
475475
expect(() =>
476476
ReactDOM.render(<input type="text" defaultValue="1" />, container),
477477
).toWarnDev(
478-
'A component is changing a controlled input of type ' +
479-
'text to be uncontrolled.',
478+
'A component is changing a controlled input to be uncontrolled.',
480479
);
481480
expect(node.value).toBe('0');
482481
});
@@ -854,8 +853,7 @@ describe('ReactDOMInput', () => {
854853
container,
855854
),
856855
).toWarnDev(
857-
'A component is changing a controlled input of type ' +
858-
'submit to be uncontrolled.',
856+
'A component is changing a controlled input to be uncontrolled.',
859857
);
860858

861859
const node = container.firstChild;
@@ -874,8 +872,7 @@ describe('ReactDOMInput', () => {
874872
container,
875873
),
876874
).toWarnDev(
877-
'A component is changing a controlled input of type ' +
878-
'reset to be uncontrolled.',
875+
'A component is changing a controlled input to be uncontrolled.',
879876
);
880877

881878
const node = container.firstChild;
@@ -1268,8 +1265,9 @@ describe('ReactDOMInput', () => {
12681265
);
12691266
ReactDOM.render(stub, container);
12701267
expect(() => ReactDOM.render(<input type="text" />, container)).toWarnDev(
1271-
'Warning: A component is changing a controlled input of type text to be uncontrolled. ' +
1272-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1268+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1269+
'This is likely caused by the value changing from undefined to ' +
1270+
'a defined value, which should not happen. ' +
12731271
'Decide between using a controlled or uncontrolled input ' +
12741272
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
12751273
' in input (at **)',
@@ -1286,8 +1284,9 @@ describe('ReactDOMInput', () => {
12861284
).toWarnDev([
12871285
'`value` prop on `input` should not be null. ' +
12881286
'Consider using an empty string to clear the component or `undefined` for uncontrolled components',
1289-
'Warning: A component is changing a controlled input of type text to be uncontrolled. ' +
1290-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1287+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1288+
'This is likely caused by the value changing from undefined to ' +
1289+
'a defined value, which should not happen. ' +
12911290
'Decide between using a controlled or uncontrolled input ' +
12921291
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
12931292
' in input (at **)',
@@ -1305,8 +1304,9 @@ describe('ReactDOMInput', () => {
13051304
container,
13061305
),
13071306
).toWarnDev(
1308-
'Warning: A component is changing a controlled input of type text to be uncontrolled. ' +
1309-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1307+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1308+
'This is likely caused by the value changing from undefined to ' +
1309+
'a defined value, which should not happen. ' +
13101310
'Decide between using a controlled or uncontrolled input ' +
13111311
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13121312
' in input (at **)',
@@ -1319,8 +1319,9 @@ describe('ReactDOMInput', () => {
13191319
expect(() =>
13201320
ReactDOM.render(<input type="text" value="controlled" />, container),
13211321
).toWarnDev(
1322-
'Warning: A component is changing an uncontrolled input of type text to be controlled. ' +
1323-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1322+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1323+
'This is likely caused by the value changing from a defined to ' +
1324+
'undefined, which should not happen. ' +
13241325
'Decide between using a controlled or uncontrolled input ' +
13251326
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13261327
' in input (at **)',
@@ -1336,8 +1337,9 @@ describe('ReactDOMInput', () => {
13361337
expect(() =>
13371338
ReactDOM.render(<input type="text" value="controlled" />, container),
13381339
).toWarnDev(
1339-
'Warning: A component is changing an uncontrolled input of type text to be controlled. ' +
1340-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1340+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1341+
'This is likely caused by the value changing from a defined to ' +
1342+
'undefined, which should not happen. ' +
13411343
'Decide between using a controlled or uncontrolled input ' +
13421344
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13431345
' in input (at **)',
@@ -1352,8 +1354,9 @@ describe('ReactDOMInput', () => {
13521354
expect(() =>
13531355
ReactDOM.render(<input type="checkbox" />, container),
13541356
).toWarnDev(
1355-
'Warning: A component is changing a controlled input of type checkbox to be uncontrolled. ' +
1356-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1357+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1358+
'This is likely caused by the value changing from undefined to ' +
1359+
'a defined value, which should not happen. ' +
13571360
'Decide between using a controlled or uncontrolled input ' +
13581361
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13591362
' in input (at **)',
@@ -1368,8 +1371,9 @@ describe('ReactDOMInput', () => {
13681371
expect(() =>
13691372
ReactDOM.render(<input type="checkbox" checked={null} />, container),
13701373
).toWarnDev(
1371-
'Warning: A component is changing a controlled input of type checkbox to be uncontrolled. ' +
1372-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1374+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1375+
'This is likely caused by the value changing from undefined to ' +
1376+
'a defined value, which should not happen. ' +
13731377
'Decide between using a controlled or uncontrolled input ' +
13741378
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13751379
' in input (at **)',
@@ -1387,8 +1391,9 @@ describe('ReactDOMInput', () => {
13871391
container,
13881392
),
13891393
).toWarnDev(
1390-
'Warning: A component is changing a controlled input of type checkbox to be uncontrolled. ' +
1391-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1394+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1395+
'This is likely caused by the value changing from undefined to ' +
1396+
'a defined value, which should not happen. ' +
13921397
'Decide between using a controlled or uncontrolled input ' +
13931398
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
13941399
' in input (at **)',
@@ -1401,8 +1406,9 @@ describe('ReactDOMInput', () => {
14011406
expect(() =>
14021407
ReactDOM.render(<input type="checkbox" checked={true} />, container),
14031408
).toWarnDev(
1404-
'Warning: A component is changing an uncontrolled input of type checkbox to be controlled. ' +
1405-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1409+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1410+
'This is likely caused by the value changing from a defined to ' +
1411+
'undefined, which should not happen. ' +
14061412
'Decide between using a controlled or uncontrolled input ' +
14071413
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14081414
' in input (at **)',
@@ -1415,8 +1421,9 @@ describe('ReactDOMInput', () => {
14151421
expect(() =>
14161422
ReactDOM.render(<input type="checkbox" checked={true} />, container),
14171423
).toWarnDev(
1418-
'Warning: A component is changing an uncontrolled input of type checkbox to be controlled. ' +
1419-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1424+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1425+
'This is likely caused by the value changing from a defined to ' +
1426+
'undefined, which should not happen. ' +
14201427
'Decide between using a controlled or uncontrolled input ' +
14211428
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14221429
' in input (at **)',
@@ -1427,8 +1434,9 @@ describe('ReactDOMInput', () => {
14271434
const stub = <input type="radio" checked={true} onChange={emptyFunction} />;
14281435
ReactDOM.render(stub, container);
14291436
expect(() => ReactDOM.render(<input type="radio" />, container)).toWarnDev(
1430-
'Warning: A component is changing a controlled input of type radio to be uncontrolled. ' +
1431-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1437+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1438+
'This is likely caused by the value changing from undefined to ' +
1439+
'a defined value, which should not happen. ' +
14321440
'Decide between using a controlled or uncontrolled input ' +
14331441
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14341442
' in input (at **)',
@@ -1441,8 +1449,9 @@ describe('ReactDOMInput', () => {
14411449
expect(() =>
14421450
ReactDOM.render(<input type="radio" checked={null} />, container),
14431451
).toWarnDev(
1444-
'Warning: A component is changing a controlled input of type radio to be uncontrolled. ' +
1445-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1452+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1453+
'This is likely caused by the value changing from undefined to ' +
1454+
'a defined value, which should not happen. ' +
14461455
'Decide between using a controlled or uncontrolled input ' +
14471456
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14481457
' in input (at **)',
@@ -1455,8 +1464,9 @@ describe('ReactDOMInput', () => {
14551464
expect(() =>
14561465
ReactDOM.render(<input type="radio" defaultChecked={true} />, container),
14571466
).toWarnDev(
1458-
'Warning: A component is changing a controlled input of type radio to be uncontrolled. ' +
1459-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1467+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1468+
'This is likely caused by the value changing from undefined to ' +
1469+
'a defined value, which should not happen. ' +
14601470
'Decide between using a controlled or uncontrolled input ' +
14611471
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14621472
' in input (at **)',
@@ -1469,8 +1479,9 @@ describe('ReactDOMInput', () => {
14691479
expect(() =>
14701480
ReactDOM.render(<input type="radio" checked={true} />, container),
14711481
).toWarnDev(
1472-
'Warning: A component is changing an uncontrolled input of type radio to be controlled. ' +
1473-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1482+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1483+
'This is likely caused by the value changing from a defined to ' +
1484+
'undefined, which should not happen. ' +
14741485
'Decide between using a controlled or uncontrolled input ' +
14751486
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14761487
' in input (at **)',
@@ -1483,8 +1494,9 @@ describe('ReactDOMInput', () => {
14831494
expect(() =>
14841495
ReactDOM.render(<input type="radio" checked={true} />, container),
14851496
).toWarnDev(
1486-
'Warning: A component is changing an uncontrolled input of type radio to be controlled. ' +
1487-
'Input elements should not switch from uncontrolled to controlled (or vice versa). ' +
1497+
'Warning: A component is changing an uncontrolled input to be controlled. ' +
1498+
'This is likely caused by the value changing from a defined to ' +
1499+
'undefined, which should not happen. ' +
14881500
'Decide between using a controlled or uncontrolled input ' +
14891501
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
14901502
' in input (at **)',
@@ -1535,8 +1547,9 @@ describe('ReactDOMInput', () => {
15351547
expect(() =>
15361548
ReactDOM.render(<input type="radio" value="value" />, container),
15371549
).toWarnDev(
1538-
'Warning: A component is changing a controlled input of type radio to be uncontrolled. ' +
1539-
'Input elements should not switch from controlled to uncontrolled (or vice versa). ' +
1550+
'Warning: A component is changing a controlled input to be uncontrolled. ' +
1551+
'This is likely caused by the value changing from undefined to ' +
1552+
'a defined value, which should not happen. ' +
15401553
'Decide between using a controlled or uncontrolled input ' +
15411554
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components\n' +
15421555
' in input (at **)',
@@ -1817,8 +1830,7 @@ describe('ReactDOMInput', () => {
18171830

18181831
it('reverts the value attribute to the initial value', () => {
18191832
expect(renderInputWithStringThenWithUndefined).toWarnDev(
1820-
'Input elements should not switch from controlled to ' +
1821-
'uncontrolled (or vice versa).',
1833+
'A component is changing a controlled input to be uncontrolled.',
18221834
);
18231835
if (disableInputAttributeSyncing) {
18241836
expect(input.getAttribute('value')).toBe(null);
@@ -1829,8 +1841,7 @@ describe('ReactDOMInput', () => {
18291841

18301842
it('preserves the value property', () => {
18311843
expect(renderInputWithStringThenWithUndefined).toWarnDev(
1832-
'Input elements should not switch from controlled to ' +
1833-
'uncontrolled (or vice versa).',
1844+
'A component is changing a controlled input to be uncontrolled.',
18341845
);
18351846
expect(input.value).toBe('latest');
18361847
});
@@ -1869,8 +1880,7 @@ describe('ReactDOMInput', () => {
18691880
'`value` prop on `input` should not be null. ' +
18701881
'Consider using an empty string to clear the component ' +
18711882
'or `undefined` for uncontrolled components.',
1872-
'Input elements should not switch from controlled ' +
1873-
'to uncontrolled (or vice versa).',
1883+
'A component is changing a controlled input to be uncontrolled.',
18741884
]);
18751885
if (disableInputAttributeSyncing) {
18761886
expect(input.hasAttribute('value')).toBe(false);
@@ -1884,8 +1894,7 @@ describe('ReactDOMInput', () => {
18841894
'`value` prop on `input` should not be null. ' +
18851895
'Consider using an empty string to clear the component ' +
18861896
'or `undefined` for uncontrolled components.',
1887-
'Input elements should not switch from controlled ' +
1888-
'to uncontrolled (or vice versa).',
1897+
'A component is changing a controlled input to be uncontrolled.',
18891898
]);
18901899
expect(input.value).toBe('latest');
18911900
});

0 commit comments

Comments
 (0)