fix(CountDown): should clear timer when destroyed (#4918)

This commit is contained in:
neverland
2019-11-04 20:16:03 +08:00
committed by GitHub
parent 577174c7f8
commit e0e597d164
2 changed files with 17 additions and 0 deletions

View File

@@ -44,6 +44,10 @@ export default createComponent({
}
},
beforeDestroy() {
this.pause();
},
methods: {
start() {
if (this.counting) {

View File

@@ -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();
});