mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(CountDown): should clear timer when deactivated (#4919)
This commit is contained in:
parent
e0e597d164
commit
b630b6b035
@ -44,6 +44,21 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
activated() {
|
||||||
|
if (this.keepAlivePaused) {
|
||||||
|
this.counting = true;
|
||||||
|
this.keepAlivePaused = false;
|
||||||
|
this.tick();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
deactivated() {
|
||||||
|
if (this.counting) {
|
||||||
|
this.pause();
|
||||||
|
this.keepAlivePaused = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.pause();
|
this.pause();
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
import CountDown from '..';
|
import CountDown from '..';
|
||||||
import { mount, later } from '../../../test/utils';
|
import { mount, later } from '../../../test/utils';
|
||||||
|
|
||||||
|
Vue.use(CountDown);
|
||||||
|
|
||||||
test('macro task finish event', async () => {
|
test('macro task finish event', async () => {
|
||||||
const wrapper = mount(CountDown, {
|
const wrapper = mount(CountDown, {
|
||||||
propsData: {
|
propsData: {
|
||||||
@ -150,15 +153,42 @@ test('incomplate format prop', () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pause when destroyed', async () => {
|
test('pause when destroyed', () => {
|
||||||
const pause = jest.fn();
|
const wrapper = mount(CountDown);
|
||||||
const wrapper = mount(CountDown, {
|
expect(wrapper.vm.counting).toBeTruthy();
|
||||||
mocks: {
|
wrapper.destroy();
|
||||||
pause
|
expect(wrapper.vm.counting).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('pause when deactivated', async () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<keep-alive>
|
||||||
|
<van-count-down v-if="render" ref="countDown" time="100" />
|
||||||
|
</keep-alive>
|
||||||
|
`,
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
render: true
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getCountDown() {
|
||||||
|
return this.$refs.countDown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.destroy();
|
const countDown = wrapper.vm.getCountDown();
|
||||||
|
expect(countDown.counting).toBeTruthy();
|
||||||
|
|
||||||
expect(wrapper.vm.counting).toBeFalsy();
|
wrapper.setData({ render: false });
|
||||||
|
expect(countDown.counting).toBeFalsy();
|
||||||
|
wrapper.setData({ render: true });
|
||||||
|
expect(countDown.counting).toBeTruthy();
|
||||||
|
|
||||||
|
countDown.pause();
|
||||||
|
wrapper.setData({ render: false });
|
||||||
|
wrapper.setData({ render: true });
|
||||||
|
expect(countDown.counting).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user