diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js index a25d8f9eff4c..c31709884641 100644 --- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js @@ -445,6 +445,93 @@ describe('ReactDOMComponent', () => { expect(node.hasAttribute('data-foo')).toBe(false); }); + if (ReactFeatureFlags.enableFilterEmptyStringAttributesDOM) { + it('should not add an empty src attribute', () => { + const container = document.createElement('div'); + expect(() => ReactDOM.render(, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `src`.', + ); + const node = container.firstChild; + expect(node.hasAttribute('src')).toBe(false); + + ReactDOM.render(, container); + expect(node.hasAttribute('src')).toBe(true); + + expect(() => ReactDOM.render(, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `src`.', + ); + expect(node.hasAttribute('src')).toBe(false); + }); + + it('should not add an empty href attribute', () => { + const container = document.createElement('div'); + expect(() => ReactDOM.render(, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `href`.', + ); + const node = container.firstChild; + expect(node.hasAttribute('href')).toBe(false); + + ReactDOM.render(, container); + expect(node.hasAttribute('href')).toBe(true); + + expect(() => ReactDOM.render(, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `href`.', + ); + expect(node.hasAttribute('href')).toBe(false); + }); + + it('should not add an empty action attribute', () => { + const container = document.createElement('div'); + expect(() => ReactDOM.render(
, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `action`.', + ); + const node = container.firstChild; + expect(node.hasAttribute('action')).toBe(false); + + ReactDOM.render(, container); + expect(node.hasAttribute('action')).toBe(true); + + expect(() => ReactDOM.render(, container)).toErrorDev( + 'Invalid value "" (empty string) for attribute `action`.', + ); + expect(node.hasAttribute('action')).toBe(false); + }); + + it('should not add an empty formAction attribute', () => { + const container = document.createElement('div'); + expect(() => + ReactDOM.render(