@samitouri / QOS-React-2 / commits / a3aae7fb01

feat:-added tests for more coverage in reactDom-input and reactText-area (#27796)

Small test similar to few tests added in #27740 , the `reactDom-input` error message was just modified to match the error message, and the `reactDomTextarea-test.js` has tests added to ensure more coverage.

BIKI DAS committed Dec 8, 2023 at 19:04 UTC a3aae7fb01ecf4ac12a8ba53abcf0403a4c7c3f8
2 files changed +93 -3
packages/react-dom/src/__tests__/ReactDOMInput-test.js
+12 -3
@@ -110,7 +110,10 @@ describe('ReactDOMInput', () => {
110 expect(() => {
111 ReactDOM.render(<input type="text" value={0} />, container);
112 }).toErrorDev(
113 - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
113 + 'Warning: You provided a `value` prop to a form ' +
114 + 'field without an `onChange` handler. This will render a read-only ' +
115 + 'field. If the field should be mutable use `defaultValue`. ' +
116 + 'Otherwise, set either `onChange` or `readOnly`.',
117 );
118 });
119
@@ -118,7 +121,10 @@ describe('ReactDOMInput', () => {
121 expect(() => {
122 ReactDOM.render(<input type="text" value="" />, container);
123 }).toErrorDev(
121 - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
124 + 'Warning: You provided a `value` prop to a form ' +
125 + 'field without an `onChange` handler. This will render a read-only ' +
126 + 'field. If the field should be mutable use `defaultValue`. ' +
127 + 'Otherwise, set either `onChange` or `readOnly`.',
128 );
129 });
130
@@ -126,7 +132,10 @@ describe('ReactDOMInput', () => {
132 expect(() => {
133 ReactDOM.render(<input type="text" value="0" />, container);
134 }).toErrorDev(
129 - 'Warning: You provided a `value` prop to a form field without an `onChange` handler.',
135 + 'Warning: You provided a `value` prop to a form ' +
136 + 'field without an `onChange` handler. This will render a read-only ' +
137 + 'field. If the field should be mutable use `defaultValue`. ' +
138 + 'Otherwise, set either `onChange` or `readOnly`.',
139 );
140 });
141
packages/react-dom/src/__tests__/ReactDOMTextarea-test.js
+81
@@ -759,4 +759,85 @@ describe('ReactDOMTextarea', () => {
759 ReactDOM.render(<textarea defaultValue={null} />, container);
760 expect(node.defaultValue).toBe('');
761 });
762 +
763 + it('should not warn about missing onChange if value is not set', () => {
764 + expect(() => {
765 + ReactTestUtils.renderIntoDocument(<textarea />);
766 + }).not.toThrow();
767 + });
768 +
769 + it('should not warn about missing onChange if value is undefined', () => {
770 + expect(() => {
771 + ReactTestUtils.renderIntoDocument(<textarea value={undefined} />);
772 + }).not.toThrow();
773 + });
774 +
775 + it('should not warn about missing onChange if onChange is set', () => {
776 + expect(() => {
777 + const change = jest.fn();
778 + ReactTestUtils.renderIntoDocument(
779 + <textarea value="something" onChange={change} />,
780 + );
781 + }).not.toThrow();
782 + });
783 +
784 + it('should not warn about missing onChange if disabled is true', () => {
785 + expect(() => {
786 + ReactTestUtils.renderIntoDocument(
787 + <textarea value="something" disabled={true} />,
788 + );
789 + }).not.toThrow();
790 + });
791 +
792 + it('should not warn about missing onChange if value is not set', () => {
793 + expect(() => {
794 + ReactTestUtils.renderIntoDocument(
795 + <textarea value="something" readOnly={true} />,
796 + );
797 + }).not.toThrow();
798 + });
799 +
800 + it('should warn about missing onChange if value is false', () => {
801 + expect(() =>
802 + ReactTestUtils.renderIntoDocument(<textarea value={false} />),
803 + ).toErrorDev(
804 + 'Warning: You provided a `value` prop to a form ' +
805 + 'field without an `onChange` handler. This will render a read-only ' +
806 + 'field. If the field should be mutable use `defaultValue`. ' +
807 + 'Otherwise, set either `onChange` or `readOnly`.',
808 + );
809 + });
810 +
811 + it('should warn about missing onChange if value is 0', () => {
812 + expect(() =>
813 + ReactTestUtils.renderIntoDocument(<textarea value={0} />),
814 + ).toErrorDev(
815 + 'Warning: You provided a `value` prop to a form ' +
816 + 'field without an `onChange` handler. This will render a read-only ' +
817 + 'field. If the field should be mutable use `defaultValue`. ' +
818 + 'Otherwise, set either `onChange` or `readOnly`.',
819 + );
820 + });
821 +
822 + it('should warn about missing onChange if value is "0"', () => {
823 + expect(() =>
824 + ReactTestUtils.renderIntoDocument(<textarea value="0" />),
825 + ).toErrorDev(
826 + 'Warning: You provided a `value` prop to a form ' +
827 + 'field without an `onChange` handler. This will render a read-only ' +
828 + 'field. If the field should be mutable use `defaultValue`. ' +
829 + 'Otherwise, set either `onChange` or `readOnly`.',
830 + );
831 + });
832 +
833 + it('should warn about missing onChange if value is ""', () => {
834 + expect(() =>
835 + ReactTestUtils.renderIntoDocument(<textarea value="" />),
836 + ).toErrorDev(
837 + 'Warning: You provided a `value` prop to a form ' +
838 + 'field without an `onChange` handler. This will render a read-only ' +
839 + 'field. If the field should be mutable use `defaultValue`. ' +
840 + 'Otherwise, set either `onChange` or `readOnly`.',
841 + );
842 + });
843 });