[Improvement] Switch: add test cases (#1202)

This commit is contained in:
neverland 2018-05-30 20:35:30 +08:00 committed by GitHub
parent 06056dc226
commit 49701851f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 68 deletions

View File

@ -46,7 +46,7 @@ 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 v-for="item in list" :key="item" :name="item"></checkbox>
</checkbox-group>
`,
components: {
@ -56,7 +56,7 @@ test('checkbox group', () => {
data() {
return {
result: [],
list: ['a', 'b', 'c', 'd']
list: ['a', 'b', 'c']
};
}
});

View File

@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ContactList render 1`] = `
<div class="van-contact-list">
<div class="van-radio-group">
<div class="van-cell-group van-hairline--top-bottom"></div>
</div>
<div class="van-hairline--top van-cell van-cell--clickable van-hairline van-contact-list__add">
<i class="van-icon van-icon-add van-cell__left-icon">
<!---->
</i>
<div class="van-cell__title"><span>新建联系人</span>
<!---->
</div>
<!---->
<i class="van-icon van-icon-arrow van-cell__right-icon">
<!---->
</i>
</div>
</div>
`;

View File

@ -1,3 +1,5 @@
import ContactCard from '..';
import ContactList from '../../contact-list';
import ContactEdit from '../../contact-edit';
import { mount } from '@vue/test-utils';
@ -6,6 +8,31 @@ const contactInfo = {
tel: '123123213'
};
describe('ContactCard', () => {
test('click event', () => {
const wrapper = mount(ContactCard, {
propsData: {
editable: false
}
});
wrapper.trigger('click');
expect(wrapper.emitted('click')).toBeFalsy();
wrapper.setProps({ editable: true });
wrapper.trigger('click');
expect(wrapper.emitted('click')).toBeTruthy();
});
});
describe('ContactList', () => {
test('render', () => {
const wrapper = mount(ContactList);
expect(wrapper.html()).toMatchSnapshot();
});
});
describe('ContactEdit', () => {
const createComponent = () => {
const wrapper = mount(ContactEdit, {
propsData: {
@ -82,3 +109,4 @@ test('delete contact', done => {
done();
});
});
});

View File

@ -0,0 +1,13 @@
import SwitchCell from '..';
import { mount } from '@vue/test-utils';
test('emit event', () => {
const wrapper = mount(SwitchCell);
wrapper.vm.$on('input', value => {
wrapper.setProps({ value });
});
wrapper.find('.van-switch').trigger('click');
expect(wrapper.emitted('change')).toBeTruthy();
});

View File

@ -0,0 +1,13 @@
import Switch from '..';
import { mount } from '@vue/test-utils';
test('emit event', () => {
const wrapper = mount(Switch);
wrapper.trigger('click');
wrapper.trigger('click');
wrapper.setProps({ disabled: true });
wrapper.trigger('click');
expect(wrapper.emitted('input')).toEqual([[true], [true]]);
expect(wrapper.emitted('change')).toEqual([[true], [true]]);
});