@samitouri / QOS-React / commits / 0452c9bba5

Add a regression test for #4618

Dan Abramov committed Aug 31, 2018 at 16:40 UTC 0452c9bba5707e4473fff17a24d36402a957dc66
1 file changed +31
packages/react-dom/src/__tests__/ReactDOMInput-test.js
+31
@@ -750,6 +750,37 @@ describe('ReactDOMInput', () => {
750 expect(handled).toBe(true);
751 });
752
753 + it('should restore uncontrolled inputs to last defaultValue upon reset', () => {
754 + const inputRef = React.createRef();
755 + ReactDOM.render(
756 + <form>
757 + <input defaultValue="default1" ref={inputRef} />
758 + <input type="reset" />
759 + </form>,
760 + container,
761 + );
762 + expect(inputRef.current.value).toBe('default1');
763 +
764 + setUntrackedValue.call(inputRef.current, 'changed');
765 + dispatchEventOnNode(inputRef.current, 'input');
766 + expect(inputRef.current.value).toBe('changed');
767 +
768 + ReactDOM.render(
769 + <form>
770 + <input defaultValue="default2" ref={inputRef} />
771 + <input type="reset" />
772 + </form>,
773 + container,
774 + );
775 + expect(inputRef.current.value).toBe('changed');
776 +
777 + container.firstChild.reset();
778 + // Note: I don't know if we want to always support this.
779 + // But it's current behavior so worth being intentional if we break it.
780 + // https://github.com/facebook/react/issues/4618
781 + expect(inputRef.current.value).toBe('default2');
782 + });
783 +
784 it('should not set a value for submit buttons unnecessarily', () => {
785 const stub = <input type="submit" />;
786 ReactDOM.render(stub, container);