mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] List: add test cases (#1191)
This commit is contained in:
parent
fc3f3bc7e0
commit
4614260e1c
@ -50,12 +50,10 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
activated() {
|
activated() {
|
||||||
/* istanbul ignore next */
|
|
||||||
this.handler(true);
|
this.handler(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivated() {
|
deactivated() {
|
||||||
/* istanbul ignore next */
|
|
||||||
this.handler(false);
|
this.handler(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
77
packages/list/test/index.spec.js
Normal file
77
packages/list/test/index.spec.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import List from '..';
|
||||||
|
import { mount } from '@vue/test-utils';
|
||||||
|
|
||||||
|
test('load event', done => {
|
||||||
|
const wrapper = mount(List);
|
||||||
|
|
||||||
|
wrapper.vm.$on('input', value => {
|
||||||
|
wrapper.vm.loading = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(wrapper.emitted('load')).toBeTruthy();
|
||||||
|
expect(wrapper.emitted('input')).toBeTruthy();
|
||||||
|
|
||||||
|
wrapper.vm.loading = false;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(wrapper.emitted('input')[1]).toBeTruthy();
|
||||||
|
wrapper.vm.$destroy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('finished', done => {
|
||||||
|
const wrapper = mount(List, {
|
||||||
|
propsData: {
|
||||||
|
finished: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(wrapper.emitted('load')).toBeFalsy();
|
||||||
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
|
wrapper.vm.finished = false;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(wrapper.emitted('load')).toBeTruthy();
|
||||||
|
expect(wrapper.emitted('input')).toBeTruthy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('immediate check false', done => {
|
||||||
|
const wrapper = mount(List, {
|
||||||
|
propsData: {
|
||||||
|
immediateCheck: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(wrapper.emitted('load')).toBeFalsy();
|
||||||
|
expect(wrapper.emitted('input')).toBeFalsy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keey-alive live cycle', () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<keep-alive>
|
||||||
|
<list v-if="show" />
|
||||||
|
</keep-alive>
|
||||||
|
`,
|
||||||
|
props: ['show'],
|
||||||
|
components: { List }
|
||||||
|
}, {
|
||||||
|
propsData: {
|
||||||
|
show: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.vm.$el).toBeTruthy();
|
||||||
|
wrapper.vm.show = false;
|
||||||
|
expect(wrapper.vm.el).toBeFalsy();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user