Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/react-dom/src/__tests__/ReactDOMAttribute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

'use strict';

// Fix JSDOM. setAttribute is supposed to throw on things that can't be implicitly toStringed.
const setAttribute = Element.prototype.setAttribute;
Element.prototype.setAttribute = function (name, value) {
// eslint-disable-next-line react-internal/safe-string-coercion
return setAttribute.call(this, name, '' + value);
};

describe('ReactDOM unknown attribute', () => {
let React;
let ReactDOMClient;
Expand Down Expand Up @@ -171,13 +178,7 @@ describe('ReactDOM unknown attribute', () => {
const test = () =>
testUnknownAttributeAssignment(new TemporalLike(), null);

if (gate('enableTrustedTypesIntegration') && !__DEV__) {
// TODO: this still throws in DEV even though it's not toString'd in prod.
await expect(test).rejects.toThrowError('2020-01-01');
} else {
await expect(test).rejects.toThrowError(new TypeError('prod message'));
}

await expect(test).rejects.toThrowError(new TypeError('prod message'));
assertConsoleErrorDev([
'The provided `unknown` attribute is an unsupported type TemporalLike.' +
' This value must be coerced to a string before using it here.\n' +
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/CheckStringCoercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ export function checkAttributeStringCoercion(
attributeName: string,
): void | string {
if (__DEV__) {
// TODO: for enableTrustedTypesIntegration we don't toString this
// so we shouldn't need the DEV warning.
if (willCoercionThrow(value)) {
console.error(
'The provided `%s` attribute is an unsupported type %s.' +
Expand Down
Loading