fix destroyFns not reduce when instance.destroy() (#14600)

* fix destroyFns not reduce when instance.destroy()

* Use object destructuring  prefer-destructuring
This commit is contained in:
郑旭 2019-01-30 10:46:30 +08:00 committed by zombieJ
parent 5ed909c9c8
commit b3df86a74f
2 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import Modal from '..';
import { destroyFns } from '../Modal'
const { confirm } = Modal;
@ -173,4 +174,26 @@ describe('Modal.confirm triggers callbacks correctly', () => {
open({ mask: false });
expect($$('.ant-modal-mask')).toHaveLength(0);
});
it('destroyFns should reduce when instance.destroy', () => {
jest.useFakeTimers();
Modal.destroyAll(); // clear destroyFns
jest.runAllTimers();
const instances = [];
['info', 'success', 'warning', 'error'].forEach(type => {
const instance = Modal[type]({
title: 'title',
content: 'content',
});
instances.push(instance)
});
const { length } = instances
instances.forEach((instance, index) => {
expect(destroyFns.length).toBe(length - index);
instance.destroy();
jest.runAllTimers();
expect(destroyFns.length).toBe(length - index - 1);
})
jest.useRealTimers();
});
});

View File

@ -154,7 +154,7 @@ export default function confirm(config: ModalFuncProps) {
}
for (let i = 0; i < destroyFns.length; i++) {
const fn = destroyFns[i];
if (fn === destroy) {
if (fn === close) {
destroyFns.splice(i, 1);
break;
}