Skip to content

Commit

Permalink
test the deprection
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Dec 21, 2020
1 parent 99f1a9d commit 6da728f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/material-ui/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,33 @@ describe('<Modal />', () => {
});
});

describe('v5 deprecations', () => {
beforeEach(() => {
PropTypes.resetWarningCache();
consoleErrorMock.spy();
});

afterEach(() => {
consoleErrorMock.reset();
});

it('should call onRendered', () => {
const handleRendered = spy();

render(
<Modal open onRendered={handleRendered}>
<div />
</Modal>,
);

expect(handleRendered).to.have.property('callCount', 1);
expect(console.error.callCount).to.equal(1);
expect(console.error.firstCall.args[0]).to.contain(
'The prop `onRendered` of `ForwardRef(Modal)` is deprecated. Use the ref instead',
);
});
});

describe('two modal at the same time', () => {
it('should open and close', () => {
const TestCase = (props) => (
Expand Down
33 changes: 33 additions & 0 deletions packages/material-ui/src/Portal/Portal.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import PropTypes from 'prop-types';
import createServerRender from 'test/utils/createServerRender';
import consoleErrorMock from 'test/utils/consoleErrorMock';
import { createClientRender } from 'test/utils/createClientRender';
Expand Down Expand Up @@ -177,6 +178,38 @@ describe('<Portal />', () => {
expect(document.querySelector('#test3').parentElement.nodeName).to.equal('BODY');
});

describe('v5 deprecations', () => {
beforeEach(() => {
PropTypes.resetWarningCache();
consoleErrorMock.spy();
});

afterEach(() => {
consoleErrorMock.reset();
});

it('should call onRendered', () => {
const ref = React.createRef();
const handleRendered = spy();
render(
<Portal
ref={ref}
onRendered={() => {
handleRendered();
expect(ref.current !== null).to.equal(true);
}}
>
<div />
</Portal>,
);
expect(handleRendered.callCount).to.equal(1);
expect(console.error.callCount).to.equal(1);
expect(console.error.firstCall.args[0]).to.contain(
'The prop `onRendered` of `ForwardRef(Portal)` is deprecated. Use the ref instead',
);
});
});

it('should call ref after child effect', () => {
const callOrder = [];
const handleRef = (node) => {
Expand Down

0 comments on commit 6da728f

Please sign in to comment.