@samitouri / QOS-React / commits / 230772f99d

[tests] Fix ReactDOMAttribute-test (#35654)

In https://github.com/facebook/react/pull/35646 I thought there was a bug in trusted types, but the bug is in jsdom. For trusted types we still want to check the coersion and throw for a good dev warning, but prod will also throw becuase the browser will implicitly coerce to a string. This ensures there's no behavior difference between dev and prod. So the right fix is to add in the JSDOM hack that's used in `ReactDOMSelect-test.js`.

Ricky committed Jan 28, 2026 at 16:00 UTC 230772f99dac80be6dda9c59441fb4928612f18e
2 files changed +8 -9
packages/react-dom/src/__tests__/ReactDOMAttribute-test.js
+8 -7
@@ -9,6 +9,13 @@
9
10 'use strict';
11
12 +// Fix JSDOM. setAttribute is supposed to throw on things that can't be implicitly toStringed.
13 +const setAttribute = Element.prototype.setAttribute;
14 +Element.prototype.setAttribute = function (name, value) {
15 + // eslint-disable-next-line react-internal/safe-string-coercion
16 + return setAttribute.call(this, name, '' + value);
17 +};
18 +
19 describe('ReactDOM unknown attribute', () => {
20 let React;
21 let ReactDOMClient;
@@ -171,13 +178,7 @@ describe('ReactDOM unknown attribute', () => {
178 const test = () =>
179 testUnknownAttributeAssignment(new TemporalLike(), null);
180
174 - if (gate('enableTrustedTypesIntegration') && !__DEV__) {
175 - // TODO: this still throws in DEV even though it's not toString'd in prod.
176 - await expect(test).rejects.toThrowError('2020-01-01');
177 - } else {
178 - await expect(test).rejects.toThrowError(new TypeError('prod message'));
179 - }
180 -
181 + await expect(test).rejects.toThrowError(new TypeError('prod message'));
182 assertConsoleErrorDev([
183 'The provided `unknown` attribute is an unsupported type TemporalLike.' +
184 ' This value must be coerced to a string before using it here.\n' +
packages/shared/CheckStringCoercion.js
-2
@@ -76,8 +76,6 @@ export function checkAttributeStringCoercion(
76 attributeName: string,
77 ): void | string {
78 if (__DEV__) {
79 - // TODO: for enableTrustedTypesIntegration we don't toString this
80 - // so we shouldn't need the DEV warning.
79 if (willCoercionThrow(value)) {
80 console.error(
81 'The provided `%s` attribute is an unsupported type %s.' +