(div = node)} className={this.props.className} />
+ );
}
}
class Grandparent extends React.Component {
@@ -71,8 +84,11 @@ describe('ReactElementClone', () => {
);
}
}
- const component = ReactTestUtils.renderIntoDocument(
);
- expect(ReactDOM.findDOMNode(component).childNodes[0].className).toBe('xyz');
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => {
+ root.render(
);
+ });
+ expect(div.className).toBe('xyz');
});
it('does not fail if config has no prototype', () => {
@@ -80,10 +96,15 @@ describe('ReactElementClone', () => {
React.cloneElement(
, config);
});
- it('should keep the original ref if it is not overridden', () => {
+ it('should keep the original ref if it is not overridden', async () => {
+ let component;
class Grandparent extends React.Component {
yoloRef = React.createRef();
+ componentDidMount() {
+ component = this;
+ }
+
render() {
return
} />;
}
@@ -97,7 +118,11 @@ describe('ReactElementClone', () => {
}
}
- const component = ReactTestUtils.renderIntoDocument(
);
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => {
+ root.render(
);
+ });
+
expect(component.yoloRef.current.tagName).toBe('DIV');
});
@@ -111,7 +136,7 @@ describe('ReactElementClone', () => {
expect(clone.key).toBe('xyz');
});
- it('should transfer children', () => {
+ it('should transfer children', async () => {
class Component extends React.Component {
render() {
expect(this.props.children).toBe('xyz');
@@ -119,12 +144,13 @@ describe('ReactElementClone', () => {
}
}
- ReactTestUtils.renderIntoDocument(
- React.cloneElement(
, {children: 'xyz'}),
- );
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => {
+ root.render(React.cloneElement(
, {children: 'xyz'}));
+ });
});
- it('should shallow clone children', () => {
+ it('should shallow clone children', async () => {
class Component extends React.Component {
render() {
expect(this.props.children).toBe('xyz');
@@ -132,9 +158,10 @@ describe('ReactElementClone', () => {
}
}
- ReactTestUtils.renderIntoDocument(
- React.cloneElement(
xyz, {}),
- );
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => {
+ root.render(React.cloneElement(
xyz, {}));
+ });
});
it('should accept children as rest arguments', () => {
@@ -174,7 +201,8 @@ describe('ReactElementClone', () => {
expect(element2.props.children).toBe(undefined);
});
- it('should support keys and refs', () => {
+ it('should support keys and refs', async () => {
+ let component;
class Parent extends React.Component {
xyzRef = React.createRef();
@@ -192,6 +220,10 @@ describe('ReactElementClone', () => {
class Grandparent extends React.Component {
parentRef = React.createRef();
+ componentDidMount() {
+ component = this;
+ }
+
render() {
return (
@@ -201,11 +233,13 @@ describe('ReactElementClone', () => {
}
}
- const component = ReactTestUtils.renderIntoDocument();
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => root.render());
expect(component.parentRef.current.xyzRef.current.tagName).toBe('SPAN');
});
- it('should steal the ref if a new ref is specified', () => {
+ it('should steal the ref if a new ref is specified', async () => {
+ let component;
class Parent extends React.Component {
xyzRef = React.createRef();
@@ -221,6 +255,10 @@ describe('ReactElementClone', () => {
parentRef = React.createRef();
childRef = React.createRef();
+ componentDidMount() {
+ component = this;
+ }
+
render() {
return (
@@ -230,12 +268,13 @@ describe('ReactElementClone', () => {
}
}
- const component = ReactTestUtils.renderIntoDocument();
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => root.render());
expect(component.childRef).toEqual({current: null});
expect(component.parentRef.current.xyzRef.current.tagName).toBe('SPAN');
});
- it('should overwrite props', () => {
+ it('should overwrite props', async () => {
class Component extends React.Component {
render() {
expect(this.props.myprop).toBe('xyz');
@@ -243,8 +282,11 @@ describe('ReactElementClone', () => {
}
}
- ReactTestUtils.renderIntoDocument(
- React.cloneElement(, {myprop: 'xyz'}),
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() =>
+ root.render(
+ React.cloneElement(, {myprop: 'xyz'}),
+ ),
);
});
@@ -287,7 +329,7 @@ describe('ReactElementClone', () => {
React.cloneElement(, null, [{}, {}]);
});
- it('should check declared prop types after clone', () => {
+ it('should check declared prop types after clone', async () => {
class Component extends React.Component {
static propTypes = {
color: PropTypes.string.isRequired,
@@ -308,8 +350,10 @@ describe('ReactElementClone', () => {
});
}
}
- expect(() =>
- ReactTestUtils.renderIntoDocument(React.createElement(GrandParent)),
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await expect(
+ async () =>
+ await act(() => root.render(React.createElement(GrandParent))),
).toErrorDev(
'Warning: Failed prop type: ' +
'Invalid prop `color` of type `number` supplied to `Component`, ' +