diff --git a/packages/react/src/__tests__/ReactElementClone-test.js b/packages/react/src/__tests__/ReactElementClone-test.js
index 4a350103d22cd..a8cf751635149 100644
--- a/packages/react/src/__tests__/ReactElementClone-test.js
+++ b/packages/react/src/__tests__/ReactElementClone-test.js
@@ -292,39 +292,38 @@ describe('ReactElementClone', () => {
}
});
+ // @gate !disableStringRefs
it('should steal the ref if a new string ref is specified without an owner', async () => {
// Regression test for this specific feature combination calling cloneElement on an element
// without an owner
- if (gate(flags => !flags.enableRefAsProp && !flags.disableStringRefs)) {
- await expect(async () => {
- // create an element without an owner
- const element = React.createElement('div', {id: 'some-id'});
- class Parent extends React.Component {
- render() {
- return {element};
- }
+ await expect(async () => {
+ // create an element without an owner
+ const element = React.createElement('div', {id: 'some-id'});
+ class Parent extends React.Component {
+ render() {
+ return {element};
}
- let child;
- class Child extends React.Component {
- render() {
- child = this;
- const clone = React.cloneElement(this.props.children, {
- ref: 'xyz',
- });
- return
{clone}
;
- }
+ }
+ let child;
+ class Child extends React.Component {
+ render() {
+ child = this;
+ const clone = React.cloneElement(this.props.children, {
+ ref: 'xyz',
+ });
+ return {clone}
;
}
+ }
- const root = ReactDOMClient.createRoot(document.createElement('div'));
- await act(() => root.render());
- expect(child.refs.xyz.tagName).toBe('DIV');
- }).toErrorDev([
- 'Warning: Component "Child" contains the string ref "xyz". Support for ' +
- 'string refs will be removed in a future major release. We recommend ' +
- 'using useRef() or createRef() instead. Learn more about using refs ' +
- 'safely here: https://react.dev/link/strict-mode-string-ref',
- ]);
- }
+ const root = ReactDOMClient.createRoot(document.createElement('div'));
+ await act(() => root.render());
+ expect(child.refs.xyz.tagName).toBe('DIV');
+ }).toErrorDev([
+ 'Warning: Component "Child" contains the string ref "xyz". Support for ' +
+ 'string refs will be removed in a future major release. We recommend ' +
+ 'using useRef() or createRef() instead. Learn more about using refs ' +
+ 'safely here: https://react.dev/link/strict-mode-string-ref',
+ ]);
});
it('should overwrite props', async () => {