mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-26 00:09:15 +08:00
[Improvement] Stepper: add test cases (#1197)
This commit is contained in:
parent
f8ccebf085
commit
5ceb044815
17
packages/stepper/test/__snapshots__/index.spec.js.snap
Normal file
17
packages/stepper/test/__snapshots__/index.spec.js.snap
Normal file
@ -0,0 +1,17 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`disable stepper input 1`] = `
|
||||
<div class="van-stepper">
|
||||
<button class="van-stepper__minus van-stepper__minus--disabled"></button>
|
||||
<input type="number" disabled="disabled" class="van-stepper__input">
|
||||
<button class="van-stepper__plus"></button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`disabled stepper 1`] = `
|
||||
<div class="van-stepper">
|
||||
<button class="van-stepper__minus van-stepper__minus--disabled"></button>
|
||||
<input type="number" disabled="disabled" class="van-stepper__input">
|
||||
<button class="van-stepper__plus van-stepper__plus--disabled"></button>
|
||||
</div>
|
||||
`;
|
94
packages/stepper/test/index.spec.js
Normal file
94
packages/stepper/test/index.spec.js
Normal file
@ -0,0 +1,94 @@
|
||||
import Stepper from '..';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
test('disabled stepper', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
disabled: true
|
||||
}
|
||||
});
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('disable stepper input', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
disableInput: true
|
||||
}
|
||||
});
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('click button', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
value: 1,
|
||||
max: 2
|
||||
}
|
||||
});
|
||||
|
||||
const plus = wrapper.find('.van-stepper__plus');
|
||||
const minus = wrapper.find('.van-stepper__minus');
|
||||
|
||||
plus.trigger('click');
|
||||
plus.trigger('click');
|
||||
minus.trigger('click');
|
||||
minus.trigger('click');
|
||||
|
||||
expect(wrapper.emitted('input')).toEqual([[2], [1]]);
|
||||
expect(wrapper.emitted('overlimit')).toEqual([['plus'], ['minus']]);
|
||||
});
|
||||
|
||||
test('correct value when value is not correct', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
value: 50,
|
||||
max: 30,
|
||||
min: 10
|
||||
}
|
||||
});
|
||||
|
||||
const input = wrapper.find('input');
|
||||
input.element.value = 1;
|
||||
input.trigger('input');
|
||||
input.element.value = 'abc';
|
||||
input.trigger('input');
|
||||
wrapper.setData({ value: 'abc' });
|
||||
input.trigger('input');
|
||||
wrapper.setData({ value: '' });
|
||||
input.trigger('input');
|
||||
wrapper.setData({ value: 40 });
|
||||
input.trigger('input');
|
||||
wrapper.setData({ value: 30 });
|
||||
input.trigger('input');
|
||||
|
||||
expect(wrapper.emitted('input')).toEqual([
|
||||
[30],
|
||||
[10],
|
||||
[''],
|
||||
[10],
|
||||
[10],
|
||||
[30],
|
||||
[30]
|
||||
]);
|
||||
});
|
||||
|
||||
test('only allow interger', () => {
|
||||
const wrapper = mount(Stepper, {
|
||||
propsData: {
|
||||
integer: true
|
||||
}
|
||||
});
|
||||
|
||||
const fn = jest.fn();
|
||||
wrapper.vm.onKeypress({
|
||||
keyCode: 46,
|
||||
preventDefault: fn
|
||||
});
|
||||
wrapper.vm.onKeypress({
|
||||
keyCode: 45,
|
||||
preventDefault: fn
|
||||
});
|
||||
|
||||
expect(fn.mock.calls.length).toEqual(1);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user