fix(Toast): onClose option should only be called once (#7496)

This commit is contained in:
neverland 2020-11-04 18:16:08 +08:00 committed by GitHub
parent 8ccee1e584
commit b9a8773a0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -108,6 +108,7 @@ function Toast(options = {}) {
if (options.onClose) {
options.onClose();
options.onClose = null;
}
if (multiple && !isServer) {

View File

@ -150,7 +150,7 @@ test('toast duration 0', () => {
Toast.allowMultiple(false);
});
test('onClose callback', () => {
test('should trigger onClose callback after closed', () => {
Toast.allowMultiple();
const onClose = jest.fn();
const toast = Toast({
@ -158,6 +158,10 @@ test('onClose callback', () => {
onClose,
});
toast.clear();
expect(onClose).toHaveBeenCalledTimes(1);
// onClose should only be called once
toast.clear();
expect(onClose).toHaveBeenCalledTimes(1);
Toast.allowMultiple(false);