Skip to content

Commit

Permalink
Convert ReactJSXElement to createRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Feb 2, 2024
1 parent 6054be9 commit be3e0d1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/react/src/__tests__/ReactJSXElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
'use strict';

let React;
let ReactDOM;
let ReactDOMClient;
let ReactTestUtils;
let act;

describe('ReactJSXElement', () => {
let Component;
Expand All @@ -20,8 +21,10 @@ describe('ReactJSXElement', () => {
jest.resetModules();

React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
act = require('internal-test-utils').act;

Component = class extends React.Component {
render() {
return <div />;
Expand Down Expand Up @@ -172,14 +175,20 @@ describe('ReactJSXElement', () => {
expect(element.constructor).toBe(object.constructor);
});

it('should use default prop value when removing a prop', () => {
it('should use default prop value when removing a prop', async () => {
Component.defaultProps = {fruit: 'persimmon'};

const container = document.createElement('div');
const instance = ReactDOM.render(<Component fruit="mango" />, container);
const root = ReactDOMClient.createRoot(container);
let instance;
await act(() => {
root.render(<Component fruit="mango" ref={ref => (instance = ref)} />);
});
expect(instance.props.fruit).toBe('mango');

ReactDOM.render(<Component />, container);
await act(() => {
root.render(<Component ref={ref => (instance = ref)} />);
});
expect(instance.props.fruit).toBe('persimmon');
});

Expand Down

0 comments on commit be3e0d1

Please sign in to comment.