[Improvement] Slider: add test cases (#1192)

This commit is contained in:
neverland
2018-05-30 14:57:14 +08:00
committed by GitHub
parent 4614260e1c
commit 92c108e245
10 changed files with 104 additions and 28 deletions

View File

@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`click bar 1`] = `
<div class="van-slider van-slider--disabled">
<div class="van-slider__bar" style="width: 50%; height: 2px;"><span class="van-slider__button"></span></div>
</div>
`;
exports[`click bar 2`] = `
<div class="van-slider">
<div class="van-slider__bar" style="width: 100%; height: 2px;"><span class="van-slider__button"></span></div>
</div>
`;
exports[`drag button 1`] = `
<div class="van-slider van-slider--disabled">
<div class="van-slider__bar" style="width: 50%; height: 2px;"><span class="van-slider__button"></span></div>
</div>
`;
exports[`drag button 2`] = `
<div class="van-slider">
<div class="van-slider__bar" style="width: 100%; height: 2px;"><span class="van-slider__button"></span></div>
</div>
`;

View File

@@ -0,0 +1,47 @@
import Slider from '..';
import { mount } from '@vue/test-utils';
import { triggerDrag, trigger } from '../../../test/utils';
Element.prototype.getBoundingClientRect = jest.fn(() => ({ width: 100, left: 0 }));
test('drag button', () => {
const wrapper = mount(Slider, {
attachToDocument: true,
propsData: {
value: 50,
disabled: true
}
});
wrapper.vm.$on('input', value => {
wrapper.setProps({ value });
});
const button = wrapper.find('.van-slider__button');
triggerDrag(button, 50, 0);
expect(wrapper.html()).toMatchSnapshot();
wrapper.setData({ disabled: false });
triggerDrag(button, 50, 0);
expect(wrapper.html()).toMatchSnapshot();
});
it('click bar', () => {
const wrapper = mount(Slider, {
propsData: {
value: 50,
disabled: true
}
});
wrapper.vm.$on('input', value => {
wrapper.setProps({ value });
});
trigger(wrapper, 'click', 100, 0);
expect(wrapper.html()).toMatchSnapshot();
wrapper.setData({ disabled: false });
trigger(wrapper, 'click', 100, 0);
expect(wrapper.html()).toMatchSnapshot();
});