Skip to content

Commit

Permalink
Remove usages of deprecated react-dom APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongarciah committed Jun 28, 2024
1 parent d204f41 commit c16bd9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable react/prefer-stateless-function */
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { expect } from 'chai';
import PropTypes from 'prop-types';
import { createRenderer, waitFor } from '@mui/internal-test-utils';
import elementAcceptingRef from './elementAcceptingRef';

describe('elementAcceptingRef', () => {
const { render } = createRenderer();

function checkPropType(element: any, required = false) {
PropTypes.checkPropTypes(
{ children: required ? elementAcceptingRef.isRequired : elementAcceptingRef },
Expand All @@ -20,35 +22,24 @@ describe('elementAcceptingRef', () => {
});

describe('acceptance when not required', () => {
let rootNode: HTMLElement;

function assertPass(element: any, { shouldMount = true } = {}) {
async function assertPass(element: any, { shouldMount = true } = {}) {
function testAct() {
checkPropType(element);
if (shouldMount) {
// TODO: replace with React 18 implementation after https://github.com/testing-library/react-testing-library/issues/1216 is closed.
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(
render(
<React.Suspense fallback={<p />}>
{React.cloneElement(element, { ref: React.createRef() })}
</React.Suspense>,
rootNode,
);
}
}

expect(testAct).not.toErrorDev();
await waitFor(() => {
expect(testAct).not.toErrorDev();
});
}

before(() => {
rootNode = document.createElement('div');
});

afterEach(() => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(rootNode);
});

it('accepts nully values', () => {
assertPass(undefined, { shouldMount: false });
assertPass(null, { shouldMount: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable react/prefer-stateless-function */
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { expect } from 'chai';
import PropTypes from 'prop-types';
import { createRenderer, waitFor } from '@mui/internal-test-utils';
import elementTypeAcceptingRef from './elementTypeAcceptingRef';

describe('elementTypeAcceptingRef', () => {
const { render } = createRenderer();

function checkPropType(elementType: any) {
PropTypes.checkPropTypes(
{ component: elementTypeAcceptingRef },
Expand All @@ -20,39 +22,28 @@ describe('elementTypeAcceptingRef', () => {
});

describe('acceptance', () => {
let rootNode: HTMLElement;

function assertPass(Component: any, { failsOnMount = false, shouldMount = true } = {}) {
async function assertPass(Component: any, { failsOnMount = false, shouldMount = true } = {}) {
function testAct() {
checkPropType(Component);
if (shouldMount) {
// TODO: replace with React 18 implementation after https://github.com/testing-library/react-testing-library/issues/1216 is closed.
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(
render(
<React.Suspense fallback={<p />}>
<Component ref={React.createRef()} />
</React.Suspense>,
rootNode,
);
}
}

if (failsOnMount) {
expect(testAct).toErrorDev('');
} else {
expect(testAct).not.toErrorDev();
}
await waitFor(() => {
if (failsOnMount) {
expect(testAct).toErrorDev('');
} else {
expect(testAct).not.toErrorDev();
}
});
}

before(() => {
rootNode = document.createElement('div');
});

afterEach(() => {
// eslint-disable-next-line react/no-deprecated
ReactDOM.unmountComponentAtNode(rootNode);
});

it('accepts nully values', () => {
assertPass(undefined, { shouldMount: false });
assertPass(null, { shouldMount: false });
Expand Down

0 comments on commit c16bd9f

Please sign in to comment.