. Add a , or to your code to match the DOM tree generated ' +
'by the browser.' +
@@ -2216,7 +2321,7 @@ describe('ReactDOMComponent', () => {
]);
});
- it('gives useful context in warnings', () => {
+ it('gives useful context in warnings', async () => {
function Row() {
return
{}} />);
+ });
+ }).toErrorDev(
'React uses onFocus and onBlur instead of onFocusIn and onFocusOut.',
);
});
- it('should warn about props that are no longer supported without case sensitivity', () => {
- ReactTestUtils.renderIntoDocument();
- expect(() =>
- ReactTestUtils.renderIntoDocument(
{}} />),
- ).toErrorDev(
+ it('should warn about props that are no longer supported without case sensitivity', async () => {
+ let container = document.createElement('div');
+ let root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render();
+ });
+
+ await expect(async () => {
+ container = document.createElement('div');
+ root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render(
{}} />);
+ });
+ }).toErrorDev(
'React uses onFocus and onBlur instead of onFocusIn and onFocusOut.',
);
- expect(() =>
- ReactTestUtils.renderIntoDocument(
,
+ );
+ });
+ }).toErrorDev([
'Invalid DOM property `class`. Did you mean `className`?\n in span (at **)',
'Invalid event handler property `onclick`. Did you mean `onClick`?\n in strong (at **)',
]);
@@ -2594,9 +2791,7 @@ describe('ReactDOMComponent', () => {
]);
});
- it('gives source code refs for unknown prop warning for exact elements in composition', () => {
- const container = document.createElement('div');
-
+ it('gives source code refs for unknown prop warning for exact elements in composition', async () => {
class Parent extends React.Component {
render() {
return (
@@ -2634,9 +2829,13 @@ describe('ReactDOMComponent', () => {
}
}
- expect(() =>
- ReactTestUtils.renderIntoDocument(, container),
- ).toErrorDev([
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render();
+ });
+ }).toErrorDev([
'Invalid DOM property `class`. Did you mean `className`?\n in span (at **)',
'Invalid event handler property `onclick`. Did you mean `onClick`?\n in strong (at **)',
]);
@@ -2692,20 +2891,26 @@ describe('ReactDOMComponent', () => {
]);
});
- it('should suggest property name if available', () => {
- expect(() =>
- ReactTestUtils.renderIntoDocument(
- React.createElement('label', {for: 'test'}),
- ),
- ).toErrorDev(
+ it('should suggest property name if available', async () => {
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render(React.createElement('label', {for: 'test'}));
+ });
+ }).toErrorDev(
'Warning: Invalid DOM property `for`. Did you mean `htmlFor`?\n in label',
);
- expect(() =>
- ReactTestUtils.renderIntoDocument(
- React.createElement('input', {type: 'text', autofocus: true}),
- ),
- ).toErrorDev(
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render(
+ React.createElement('input', {type: 'text', autofocus: true}),
+ );
+ });
+ }).toErrorDev(
'Warning: Invalid DOM property `autofocus`. Did you mean `autoFocus`?\n in input',
);
});
@@ -2762,10 +2967,15 @@ describe('ReactDOMComponent', () => {
});
describe('Attributes with aliases', function () {
- it('sets aliased attributes on HTML attributes', function () {
+ it('sets aliased attributes on HTML attributes', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Warning: Invalid DOM property `class`. Did you mean `className`?',
);
@@ -2773,10 +2983,15 @@ describe('ReactDOMComponent', () => {
expect(el.className).toBe('test');
});
- it('sets incorrectly cased aliased attributes on HTML attributes with a warning', function () {
+ it('sets incorrectly cased aliased attributes on HTML attributes with a warning', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Warning: Invalid DOM property `cLASS`. Did you mean `className`?',
);
@@ -2784,14 +2999,19 @@ describe('ReactDOMComponent', () => {
expect(el.className).toBe('test');
});
- it('sets aliased attributes on SVG elements with a warning', function () {
+ it('sets aliased attributes on SVG elements with a warning', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument(
- ,
- );
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
+ ,
+ );
+ });
}).toErrorDev(
'Warning: Invalid DOM property `arabic-form`. Did you mean `arabicForm`?',
);
@@ -2800,18 +3020,26 @@ describe('ReactDOMComponent', () => {
expect(text.hasAttribute('arabic-form')).toBe(true);
});
- it('sets aliased attributes on custom elements', function () {
- const el = ReactTestUtils.renderIntoDocument(
- ,
- );
+ it('sets aliased attributes on custom elements', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+ await act(() => {
+ root.render();
+ });
+ const el = container.firstChild;
expect(el.getAttribute('class')).toBe('test');
});
- it('aliased attributes on custom elements with bad casing', function () {
- const el = ReactTestUtils.renderIntoDocument(
- ,
- );
+ it('aliased attributes on custom elements with bad casing', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('class')).toBe('test');
});
@@ -2831,8 +3059,15 @@ describe('ReactDOMComponent', () => {
});
describe('Custom attributes', function () {
- it('allows assignment of custom attributes with string values', () => {
- const el = ReactTestUtils.renderIntoDocument();
+ it('allows assignment of custom attributes with string values', async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('whatever')).toBe('30');
});
@@ -2853,10 +3088,15 @@ describe('ReactDOMComponent', () => {
expect(container.firstChild.hasAttribute('whatever')).toBe(false);
});
- it('does not assign a boolean custom attributes as a string', function () {
+ it('does not assign a boolean custom attributes as a string', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Received `true` for a non-boolean attribute `whatever`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
@@ -2866,11 +3106,18 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);
});
- it('does not assign an implicit boolean custom attributes', function () {
+ it('does not assign an implicit boolean custom attributes', async function () {
let el;
- expect(() => {
- // eslint-disable-next-line react/jsx-boolean-value
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
+ // eslint-disable-next-line react/jsx-boolean-value
+
(el = current)} />,
+ );
+ });
}).toErrorDev(
'Received `true` for a non-boolean attribute `whatever`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
@@ -2880,23 +3127,44 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);
});
- it('assigns a numeric custom attributes as a string', function () {
- const el = ReactTestUtils.renderIntoDocument();
+ it('assigns a numeric custom attributes as a string', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('whatever')).toBe('3');
});
- it('will not assign a function custom attributes', function () {
+ it('will not assign a function custom attributes', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument(
(el = current)} />,
+ );
+ });
}).toErrorDev(
'React does not recognize the `data-fooBar` prop on a DOM element. ' +
'If you intentionally want it to appear in the DOM as a custom ' +
@@ -2939,10 +3214,15 @@ describe('ReactDOMComponent', () => {
expect(el.getAttribute('data-foobar')).toBe('true');
});
- it('allows cased custom attributes', () => {
+ it('allows cased custom attributes', async () => {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'React does not recognize the `fooBar` prop on a DOM element. ' +
'If you intentionally want it to appear in the DOM as a custom ' +
@@ -2954,10 +3234,15 @@ describe('ReactDOMComponent', () => {
expect(el.getAttribute('foobar')).toBe('true');
});
- it('warns on NaN attributes', () => {
+ it('warns on NaN attributes', async () => {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Warning: Received NaN for the `whatever` attribute. If this is ' +
'expected, cast the value to a string.\n in div',
@@ -2981,10 +3266,15 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);
});
- it('warns on bad casing of known HTML attributes', function () {
+ it('warns on bad casing of known HTML attributes', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Warning: Invalid DOM property `SiZe`. Did you mean `size`?',
);
@@ -2994,8 +3284,15 @@ describe('ReactDOMComponent', () => {
});
describe('Object stringification', function () {
- it('allows objects on known properties', function () {
- const el = ReactTestUtils.renderIntoDocument();
+ it('allows objects on known properties', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('accept-charset')).toBe('[object Object]');
});
@@ -3050,27 +3347,46 @@ describe('ReactDOMComponent', () => {
);
});
- it('allows objects that inherit a custom toString method', function () {
+ it('allows objects that inherit a custom toString method', async function () {
const parent = {toString: () => 'hello.jpg'};
const child = Object.create(parent);
- const el = ReactTestUtils.renderIntoDocument();
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.src).toBe('http://localhost/hello.jpg');
});
- it('assigns ajaxify (an important internal FB attribute)', function () {
+ it('assigns ajaxify (an important internal FB attribute)', async function () {
const options = {toString: () => 'ajaxy'};
- const el = ReactTestUtils.renderIntoDocument();
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('ajaxify')).toBe('ajaxy');
});
});
describe('String boolean attributes', function () {
- it('does not assign string boolean attributes for custom attributes', function () {
+ it('does not assign string boolean attributes for custom attributes', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Received `true` for a non-boolean attribute `whatever`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
@@ -3080,31 +3396,57 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);
});
- it('stringifies the boolean true for allowed attributes', function () {
- const el = ReactTestUtils.renderIntoDocument();
+ it('stringifies the boolean true for allowed attributes', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('spellCheck')).toBe('true');
});
- it('stringifies the boolean false for allowed attributes', function () {
- const el = ReactTestUtils.renderIntoDocument();
+ it('stringifies the boolean false for allowed attributes', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('spellCheck')).toBe('false');
});
- it('stringifies implicit booleans for allowed attributes', function () {
- // eslint-disable-next-line react/jsx-boolean-value
- const el = ReactTestUtils.renderIntoDocument();
+ it('stringifies implicit booleans for allowed attributes', async function () {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ // eslint-disable-next-line react/jsx-boolean-value
+ root.render();
+ });
+
+ const el = container.firstChild;
expect(el.getAttribute('spellCheck')).toBe('true');
});
});
describe('Boolean attributes', function () {
- it('warns on the ambiguous string value "false"', function () {
+ it('warns on the ambiguous string value "false"', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Received the string `false` for the boolean attribute `hidden`. ' +
'The browser will interpret it as a truthy value. ' +
@@ -3114,10 +3456,15 @@ describe('ReactDOMComponent', () => {
expect(el.getAttribute('hidden')).toBe('');
});
- it('warns on the potentially-ambiguous string value "true"', function () {
+ it('warns on the potentially-ambiguous string value "true"', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument();
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
(el = current)} />);
+ });
}).toErrorDev(
'Received the string `true` for the boolean attribute `hidden`. ' +
'Although this works, it will not work as expected if you pass the string "false". ' +
@@ -3129,14 +3476,19 @@ describe('ReactDOMComponent', () => {
});
describe('Hyphenated SVG elements', function () {
- it('the font-face element is not a custom element', function () {
+ it('the font-face element is not a custom element', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument(
- ,
- );
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
+ ,
+ );
+ });
}).toErrorDev(
'Warning: Invalid DOM property `x-height`. Did you mean `xHeight`',
);
@@ -3146,14 +3498,19 @@ describe('ReactDOMComponent', () => {
);
});
- it('the font-face element does not allow unknown boolean values', function () {
+ it('the font-face element does not allow unknown boolean values', async function () {
let el;
- expect(() => {
- el = ReactTestUtils.renderIntoDocument(
- ,
- );
+ await expect(async () => {
+ const container = document.createElement('div');
+ const root = ReactDOMClient.createRoot(container);
+
+ await act(() => {
+ root.render(
+ ,
+ );
+ });
}).toErrorDev(
'Received `false` for a non-boolean attribute `whatever`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
@@ -3324,7 +3681,7 @@ describe('ReactDOMComponent', () => {
expect(typeof portalContainer.onclick).toBe('function');
});
- it('does not add onclick handler to the React root', () => {
+ it('does not add onclick handler to the React root in legacy mode', () => {
const container = document.createElement('div');
function Component() {