mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +08:00
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:
parent
5ed909c9c8
commit
b3df86a74f
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user