Skip to content

Commit

Permalink
Remove RTR from ReactCreateRef-test (#28386)
Browse files Browse the repository at this point in the history
## Summary

Cleaning up internal usage of ReactTestRenderer

## How did you test this change?

`yarn test packages/react/src/__tests__/ReactCreateRef-test.js`
  • Loading branch information
jackpope authored Feb 20, 2024
1 parent 0778f61 commit 3b26000
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/react/src/__tests__/ReactCreateRef-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
'use strict';

let React;
let ReactTestRenderer;
let ReactDOM;
let ReactDOMClient;

describe('ReactCreateRef', () => {
beforeEach(() => {
jest.resetModules();

React = require('react');
ReactTestRenderer = require('react-test-renderer');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
});

it('should warn in dev if an invalid ref object is provided', () => {
Expand All @@ -31,12 +33,15 @@ describe('ReactCreateRef', () => {
}
}

const root = ReactDOMClient.createRoot(document.createElement('div'));
expect(() =>
ReactTestRenderer.create(
<Wrapper>
<div ref={{}} />
</Wrapper>,
),
ReactDOM.flushSync(() => {
root.render(
<Wrapper>
<div ref={{}} />
</Wrapper>,
);
}),
).toErrorDev(
'Unexpected ref object provided for div. ' +
'Use either a ref-setter function or React.createRef().\n' +
Expand All @@ -45,11 +50,13 @@ describe('ReactCreateRef', () => {
);

expect(() =>
ReactTestRenderer.create(
<Wrapper>
<ExampleComponent ref={{}} />
</Wrapper>,
),
ReactDOM.flushSync(() => {
root.render(
<Wrapper>
<ExampleComponent ref={{}} />
</Wrapper>,
);
}),
).toErrorDev(
'Unexpected ref object provided for ExampleComponent. ' +
'Use either a ref-setter function or React.createRef().\n' +
Expand Down

0 comments on commit 3b26000

Please sign in to comment.