Skip to content

Commit

Permalink
Fixed warning when unmounting animated modals
Browse files Browse the repository at this point in the history
Signed-off-by: Reid Mitchell <rmitchell@pivotal.io>
  • Loading branch information
sjolicoeur authored and pivotal committed Oct 17, 2017
1 parent 8ac9be5 commit 1e0fa81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions spec/pivotal-ui-react/modals/modals_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../spec_helper';
import {findByClass, findAllByClass, clickOn} from '../spec_helper';
import {Modal, BaseModal} from '../../../src/react/modals';
import AnimationMixin from 'pui-react-animation';

let result;

Expand Down Expand Up @@ -238,6 +239,20 @@ describe('BaseModal', () => {

expect(onHide).not.toHaveBeenCalled();
});

describe('when animation is true', () => {
beforeEach(() => {
spyOn(AnimationMixin, 'componentWillUnmount').and.callThrough();
});

it('resets animation if unmounted before animation finishes', () => {
result = renderIntoDom({show: true, onHide, animation: true});
ReactDOM.unmountComponentAtNode(root);
MockRaf.next();

expect(AnimationMixin.componentWillUnmount).toHaveBeenCalled();
});
});
});

describe('acquireFocus', () => {
Expand Down
1 change: 1 addition & 0 deletions src/react/modals/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
}

componentWillUnmount() {
if (super.componentWillUnmount) super.componentWillUnmount();
const document = this.props.getDocument();
if (typeof document !== 'object') return;
document.removeEventListener('keydown', this.onKeyDown);
Expand Down

0 comments on commit 1e0fa81

Please sign in to comment.