test(PullRefresh): add test cases

This commit is contained in:
陈嘉涵 2019-12-27 14:21:49 +08:00 committed by neverland
parent e00058b681
commit f3857053d6
3 changed files with 58 additions and 4 deletions

View File

@ -192,3 +192,5 @@ export default createComponent({
);
}
});
//

View File

@ -79,3 +79,21 @@ exports[`not in page top 1`] = `
</div>
</div>
`;
exports[`render success text 1`] = `
<div class="van-pull-refresh">
<div class="van-pull-refresh__track" style="transition-duration: 300ms; transform: translate3d(0,50px, 0);">
<div class="van-pull-refresh__head">
<div class="van-pull-refresh__text">success</div>
</div>
</div>
</div>
`;
exports[`render success text 2`] = `
<div class="van-pull-refresh">
<div class="van-pull-refresh__track" style="transition-duration: 300ms;">
<div class="van-pull-refresh__head"></div>
</div>
</div>
`;

View File

@ -5,13 +5,14 @@ test('change head content when pulling down', async () => {
const wrapper = mount(PullRefresh, {
propsData: {
value: false
},
listeners: {
input(value) {
wrapper.setProps({ value });
}
}
});
wrapper.vm.$on('input', value => {
wrapper.vm.value = value;
});
const track = wrapper.find('.van-pull-refresh__track');
// pulling
@ -65,6 +66,7 @@ test('custom content by slots', async () => {
expect(wrapper).toMatchSnapshot();
// loosing
trigger(track, 'touchmove', 0, 75);
trigger(track, 'touchmove', 0, 100);
expect(wrapper).toMatchSnapshot();
@ -102,3 +104,35 @@ test('not in page top', () => {
expect(wrapper).toMatchSnapshot();
});
test('render success text', async () => {
const wrapper = mount(PullRefresh, {
propsData: {
successText: 'success',
successDuration: 0
},
listeners: {
input(value) {
wrapper.setProps({ value });
}
}
});
const track = wrapper.find('.van-pull-refresh__track');
trigger(track, 'touchstart', 0, 0);
trigger(track, 'touchmove', 0, 100);
trigger(track, 'touchend', 0, 100);
await later();
// loading
expect(wrapper.vm.value).toBeTruthy();
wrapper.setProps({ value: false });
// success
expect(wrapper).toMatchSnapshot();
// normal
await later();
expect(wrapper).toMatchSnapshot();
});