Skip to content

Commit

Permalink
[test] Migrate Fade to react-testing-library (#22918)
Browse files Browse the repository at this point in the history
  • Loading branch information
eladmotola committed Oct 7, 2020
1 parent 81aba1c commit 25801be
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions packages/material-ui/src/Fade/Fade.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy, useFakeTimers } from 'sinon';
import { createMount, describeConformance } from 'test/utils';
import { createClientRender, createMount, describeConformance } from 'test/utils';
import { Transition } from 'react-transition-group';
import Fade from './Fade';

describe('<Fade />', () => {
const render = createClientRender();
const mount = createMount({ strict: true });

const defaultProps = {
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('<Fade />', () => {
const handleExiting = spy();
const handleExited = spy();

const wrapper = mount(
const { container, setProps } = render(
<Fade
onEnter={handleEnter}
onEntering={handleEntering}
Expand All @@ -57,64 +58,66 @@ describe('<Fade />', () => {
<div id="test" />
</Fade>,
);
const child = wrapper.find('#test');
const child = container.querySelector('#test');

wrapper.setProps({ in: true });
setProps({ in: true });

expect(handleEnter.callCount).to.equal(1);
expect(handleEnter.args[0][0]).to.equal(child.instance());
expect(handleEnter.args[0][0]).to.equal(child);
expect(handleEnter.args[0][0].style.transition).to.match(
/opacity 225ms cubic-bezier\(0.4, 0, 0.2, 1\)( 0ms)?/,
);

expect(handleEntering.callCount).to.equal(1);
expect(handleEntering.args[0][0]).to.equal(child.instance());
expect(handleEntering.args[0][0]).to.equal(child);

clock.tick(1000);
expect(handleEntered.callCount).to.equal(1);
expect(handleEntered.args[0][0]).to.equal(child.instance());
expect(handleEntered.args[0][0]).to.equal(child);

wrapper.setProps({ in: false });
setProps({ in: false });

expect(handleExit.callCount).to.equal(1);
expect(handleExit.args[0][0]).to.equal(child.instance());
expect(handleExit.args[0][0]).to.equal(child);

expect(handleExit.args[0][0].style.transition).to.match(
/opacity 195ms cubic-bezier\(0.4, 0, 0.2, 1\)( 0ms)?/,
);

expect(handleExiting.callCount).to.equal(1);
expect(handleExiting.args[0][0]).to.equal(child.instance());
expect(handleExiting.args[0][0]).to.equal(child);

clock.tick(1000);
expect(handleExited.callCount).to.equal(1);
expect(handleExited.args[0][0]).to.equal(child.instance());
expect(handleExited.args[0][0]).to.equal(child);
});
});

describe('prop: appear', () => {
it('should work when initially hidden, appear=true', () => {
const wrapper = mount(
const { container } = render(
<Fade in={false} appear>
<div>Foo</div>
</Fade>,
);
expect(wrapper.find('div').props().style).to.deep.equal({
opacity: 0,
visibility: 'hidden',
});

const element = container.querySelector('div');

expect(element.style).to.have.property('opacity', '0');
expect(element.style).to.have.property('visibility', 'hidden');
});

it('should work when initially hidden, appear=false', () => {
const wrapper = mount(
const { container } = render(
<Fade in={false} appear={false}>
<div>Foo</div>
</Fade>,
);
expect(wrapper.find('div').props().style).to.deep.equal({
opacity: 0,
visibility: 'hidden',
});

const element = container.querySelector('div');

expect(element.style).to.have.property('opacity', '0');
expect(element.style).to.have.property('visibility', 'hidden');
});
});
});

0 comments on commit 25801be

Please sign in to comment.