Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,9 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
* should control radio buttons
* should control radio buttons if the tree updates during render
* should warn with value and no onChange handler and readOnly specified
* should warn with an empty value and no onChange handler and readOnly specified
* should warn with a value of number `0` and no onChange handler and readOnly specified
* should warn with a value of `false` and no onChange handler and readOnly specified
* should have a this value of undefined if bind is not used
* should warn with checked and no onChange handler with readOnly specified
* should update defaultValue to empty string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (__DEV__) {
var propTypes = {
value: function(props, propName, componentName) {
if (
!props[propName] ||
props[propName] == null ||
hasReadOnlyValue[props.type] ||
props.onChange ||
props.readOnly ||
Expand All @@ -52,7 +52,7 @@ if (__DEV__) {
},
checked: function(props, propName, componentName) {
if (
!props[propName] ||
props[propName] == null ||
props.onChange ||
props.readOnly ||
props.disabled
Expand Down
61 changes: 59 additions & 2 deletions src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,63 @@ describe('ReactDOMInput', () => {
);
});

it('should warn with an empty value and no onChange handler and readOnly specified', () => {
ReactTestUtils.renderIntoDocument(
<input type="text" value="" readOnly={true} />,
);
expectDev(console.error.calls.count()).toBe(0);

ReactTestUtils.renderIntoDocument(
<input type="text" value="" readOnly={false} />,
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed form propType: 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`.\n' +
' in input (at **)',
);
});

it('should warn with a value of number `0` and no onChange handler and readOnly specified', () => {
ReactTestUtils.renderIntoDocument(
<input type="text" value={0} readOnly={true} />,
);
expectDev(console.error.calls.count()).toBe(0);

ReactTestUtils.renderIntoDocument(
<input type="text" value={0} readOnly={false} />,
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed form propType: 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`.\n' +
' in input (at **)',
);
});

it('should warn with a value of `false` and no onChange handler and readOnly specified', () => {
ReactTestUtils.renderIntoDocument(
<input type="text" value={false} readOnly={true} />,
);
expectDev(console.error.calls.count()).toBe(0);

ReactTestUtils.renderIntoDocument(
<input type="text" value={false} readOnly={false} />,
);
expectDev(console.error.calls.count()).toBe(1);
expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed form propType: 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`.\n' +
' in input (at **)',
);
});

it('should have a this value of undefined if bind is not used', () => {
var unboundInputOnChange = function() {
expect(this).toBe(undefined);
Expand All @@ -793,12 +850,12 @@ describe('ReactDOMInput', () => {

it('should warn with checked and no onChange handler with readOnly specified', () => {
ReactTestUtils.renderIntoDocument(
<input type="checkbox" checked="false" readOnly={true} />,
<input type="checkbox" checked={false} readOnly={true} />,
);
expectDev(console.error.calls.count()).toBe(0);

ReactTestUtils.renderIntoDocument(
<input type="checkbox" checked="false" readOnly={false} />,
<input type="checkbox" checked={false} readOnly={false} />,
);
expectDev(console.error.calls.count()).toBe(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('ReactDOMTextarea', () => {
});

it('should display `value` of number 0', () => {
var stub = <textarea value={0} />;
var stub = <textarea value={0} onChange={emptyFunction} />;
var node = renderTextarea(stub);

expect(node.value).toBe('0');
Expand Down