mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 03:44:48 +00:00
[Improvement] Checkbox: add test cases (#1201)
This commit is contained in:
72
packages/checkbox/test/index.spec.js
Normal file
72
packages/checkbox/test/index.spec.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import Checkbox from '..';
|
||||
import CheckboxGroup from '../../checkbox-group';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
test('switch checkbox', () => {
|
||||
const wrapper = mount(Checkbox);
|
||||
|
||||
wrapper.vm.$on('input', value => {
|
||||
wrapper.setData({ value });
|
||||
});
|
||||
|
||||
const icon = wrapper.find('.van-checkbox__icon');
|
||||
icon.trigger('click');
|
||||
icon.trigger('click');
|
||||
|
||||
expect(wrapper.emitted('input')).toEqual([[true], [false]]);
|
||||
expect(wrapper.emitted('change')).toEqual([[true], [false]]);
|
||||
});
|
||||
|
||||
test('disabled', () => {
|
||||
const wrapper = mount(Checkbox, {
|
||||
propsData: {
|
||||
disabled: true
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.find('.van-checkbox__icon').trigger('click');
|
||||
expect(wrapper.emitted('input')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('label disabled', () => {
|
||||
const wrapper = mount(Checkbox, {
|
||||
slots: {
|
||||
default: '<div />'
|
||||
},
|
||||
propsData: {
|
||||
labelDisabled: true
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.find('.van-checkbox__label').trigger('click');
|
||||
expect(wrapper.emitted('input')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('checkbox group', () => {
|
||||
const wrapper = mount({
|
||||
template: `
|
||||
<checkbox-group v-model="result" :max="2">
|
||||
<checkbox v-for="item in list" :key="item" :name="item" :disabled="item === 'd'"></checkbox>
|
||||
</checkbox-group>
|
||||
`,
|
||||
components: {
|
||||
Checkbox,
|
||||
CheckboxGroup
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
result: [],
|
||||
list: ['a', 'b', 'c', 'd']
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
const icons = wrapper.findAll('.van-checkbox__icon');
|
||||
icons.at(0).trigger('click');
|
||||
icons.at(1).trigger('click');
|
||||
icons.at(2).trigger('click');
|
||||
expect(wrapper.vm.result).toEqual(['a', 'b']);
|
||||
|
||||
icons.at(0).trigger('click');
|
||||
expect(wrapper.vm.result).toEqual(['b']);
|
||||
});
|
Reference in New Issue
Block a user