diff --git a/src/toast/index.js b/src/toast/index.js index 514a45202..33a022a54 100644 --- a/src/toast/index.js +++ b/src/toast/index.js @@ -108,6 +108,7 @@ function Toast(options = {}) { if (options.onClose) { options.onClose(); + options.onClose = null; } if (multiple && !isServer) { diff --git a/src/toast/test/index.spec.js b/src/toast/test/index.spec.js index 3026877ef..3b0584969 100644 --- a/src/toast/test/index.spec.js +++ b/src/toast/test/index.spec.js @@ -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);