diff --git a/packages/react-dom/src/__tests__/ReactDOMInput-test.js b/packages/react-dom/src/__tests__/ReactDOMInput-test.js
index be4b59ce0806e..6b8baaddbe023 100644
--- a/packages/react-dom/src/__tests__/ReactDOMInput-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMInput-test.js
@@ -110,7 +110,10 @@ describe('ReactDOMInput', () => {
expect(() => {
ReactDOM.render(, container);
}).toErrorDev(
- 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
);
});
@@ -118,7 +121,10 @@ describe('ReactDOMInput', () => {
expect(() => {
ReactDOM.render(, container);
}).toErrorDev(
- 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
);
});
@@ -126,7 +132,10 @@ describe('ReactDOMInput', () => {
expect(() => {
ReactDOM.render(, container);
}).toErrorDev(
- 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
);
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
index 39a1bac1e9ede..810452c64a313 100644
--- a/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
@@ -759,4 +759,85 @@ describe('ReactDOMTextarea', () => {
ReactDOM.render(, container);
expect(node.defaultValue).toBe('');
});
+
+ it('should not warn about missing onChange if value is not set', () => {
+ expect(() => {
+ ReactTestUtils.renderIntoDocument();
+ }).not.toThrow();
+ });
+
+ it('should not warn about missing onChange if value is undefined', () => {
+ expect(() => {
+ ReactTestUtils.renderIntoDocument();
+ }).not.toThrow();
+ });
+
+ it('should not warn about missing onChange if onChange is set', () => {
+ expect(() => {
+ const change = jest.fn();
+ ReactTestUtils.renderIntoDocument(
+ ,
+ );
+ }).not.toThrow();
+ });
+
+ it('should not warn about missing onChange if disabled is true', () => {
+ expect(() => {
+ ReactTestUtils.renderIntoDocument(
+ ,
+ );
+ }).not.toThrow();
+ });
+
+ it('should not warn about missing onChange if value is not set', () => {
+ expect(() => {
+ ReactTestUtils.renderIntoDocument(
+ ,
+ );
+ }).not.toThrow();
+ });
+
+ it('should warn about missing onChange if value is false', () => {
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(),
+ ).toErrorDev(
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
+ );
+ });
+
+ it('should warn about missing onChange if value is 0', () => {
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(),
+ ).toErrorDev(
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
+ );
+ });
+
+ it('should warn about missing onChange if value is "0"', () => {
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(),
+ ).toErrorDev(
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
+ );
+ });
+
+ it('should warn about missing onChange if value is ""', () => {
+ expect(() =>
+ ReactTestUtils.renderIntoDocument(),
+ ).toErrorDev(
+ 'Warning: You provided a `value` prop to a form ' +
+ 'field without an `onChange` handler. This will render a read-only ' +
+ 'field. If the field should be mutable use `defaultValue`. ' +
+ 'Otherwise, set either `onChange` or `readOnly`.',
+ );
+ });
});