Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ReactJSXElement to createRoot #28208

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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