Skip to content

Commit

Permalink
Add a regression test for facebook#4618
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and jetoneza committed Jan 23, 2019
1 parent 9097440 commit 89bfc88
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,37 @@ describe('ReactDOMInput', () => {
expect(handled).toBe(true);
});

it('should restore uncontrolled inputs to last defaultValue upon reset', () => {
const inputRef = React.createRef();
ReactDOM.render(
<form>
<input defaultValue="default1" ref={inputRef} />
<input type="reset" />
</form>,
container,
);
expect(inputRef.current.value).toBe('default1');

setUntrackedValue.call(inputRef.current, 'changed');
dispatchEventOnNode(inputRef.current, 'input');
expect(inputRef.current.value).toBe('changed');

ReactDOM.render(
<form>
<input defaultValue="default2" ref={inputRef} />
<input type="reset" />
</form>,
container,
);
expect(inputRef.current.value).toBe('changed');

container.firstChild.reset();
// Note: I don't know if we want to always support this.
// But it's current behavior so worth being intentional if we break it.
// https://github.com/facebook/react/issues/4618
expect(inputRef.current.value).toBe('default2');
});

it('should not set a value for submit buttons unnecessarily', () => {
const stub = <input type="submit" />;
ReactDOM.render(stub, container);
Expand Down

0 comments on commit 89bfc88

Please sign in to comment.