mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 10:56:35 +08:00
fix(Toast): onClose option should only be called once (#7496)
This commit is contained in:
parent
8ccee1e584
commit
b9a8773a0a
@ -108,6 +108,7 @@ function Toast(options = {}) {
|
|||||||
|
|
||||||
if (options.onClose) {
|
if (options.onClose) {
|
||||||
options.onClose();
|
options.onClose();
|
||||||
|
options.onClose = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiple && !isServer) {
|
if (multiple && !isServer) {
|
||||||
|
@ -150,7 +150,7 @@ test('toast duration 0', () => {
|
|||||||
Toast.allowMultiple(false);
|
Toast.allowMultiple(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('onClose callback', () => {
|
test('should trigger onClose callback after closed', () => {
|
||||||
Toast.allowMultiple();
|
Toast.allowMultiple();
|
||||||
const onClose = jest.fn();
|
const onClose = jest.fn();
|
||||||
const toast = Toast({
|
const toast = Toast({
|
||||||
@ -158,6 +158,10 @@ test('onClose callback', () => {
|
|||||||
onClose,
|
onClose,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toast.clear();
|
||||||
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
// onClose should only be called once
|
||||||
toast.clear();
|
toast.clear();
|
||||||
expect(onClose).toHaveBeenCalledTimes(1);
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
Toast.allowMultiple(false);
|
Toast.allowMultiple(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user