From e0e597d164bc644a7cc3aecac7d445a905726341 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 4 Nov 2019 20:16:03 +0800 Subject: [PATCH] fix(CountDown): should clear timer when destroyed (#4918) --- src/count-down/index.js | 4 ++++ src/count-down/test/index.spec.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/count-down/index.js b/src/count-down/index.js index f60912b1c..5b75b6817 100644 --- a/src/count-down/index.js +++ b/src/count-down/index.js @@ -44,6 +44,10 @@ export default createComponent({ } }, + beforeDestroy() { + this.pause(); + }, + methods: { start() { if (this.counting) { diff --git a/src/count-down/test/index.spec.js b/src/count-down/test/index.spec.js index 1436ee270..bef0f6058 100644 --- a/src/count-down/test/index.spec.js +++ b/src/count-down/test/index.spec.js @@ -149,3 +149,16 @@ test('incomplate format prop', () => { expect(wrapper).toMatchSnapshot(); }); + +test('pause when destroyed', async () => { + const pause = jest.fn(); + const wrapper = mount(CountDown, { + mocks: { + pause + } + }); + + wrapper.destroy(); + + expect(wrapper.vm.counting).toBeFalsy(); +});