mirror of
https://github.com/youzan/vant.git
synced 2025-12-22 01:07:29 +08:00
simplify test config (#639)
This commit is contained in:
95
test/specs/switch-cell.spec.js
Normal file
95
test/specs/switch-cell.spec.js
Normal file
@@ -0,0 +1,95 @@
|
||||
import SwitchCell from 'packages/switch-cell';
|
||||
import { mount } from 'avoriaz';
|
||||
import { DOMChecker } from '../utils';
|
||||
|
||||
describe('SwitchCell', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('default', () => {
|
||||
wrapper = mount(SwitchCell, {
|
||||
attachToDocument: true
|
||||
});
|
||||
|
||||
DOMChecker(wrapper, {
|
||||
count: {
|
||||
'.van-switch--off': 1,
|
||||
'.van-switch--disabled': 0
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('set title', () => {
|
||||
wrapper = mount(SwitchCell, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
title: '测试标题'
|
||||
}
|
||||
});
|
||||
|
||||
DOMChecker(wrapper, {
|
||||
text: {
|
||||
'.van-cell__text': '测试标题'
|
||||
},
|
||||
count: {
|
||||
'.van-switch--off': 1,
|
||||
'.van-switch--disabled': 0
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('checked', () => {
|
||||
wrapper = mount(SwitchCell, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
value: true
|
||||
}
|
||||
});
|
||||
|
||||
DOMChecker(wrapper, {
|
||||
count: {
|
||||
'.van-switch--on': 1,
|
||||
'.van-switch--disabled': 0
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('disabled', () => {
|
||||
wrapper = mount(SwitchCell, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
disabled: true
|
||||
}
|
||||
});
|
||||
|
||||
DOMChecker(wrapper, {
|
||||
count: {
|
||||
'.van-switch--off': 1,
|
||||
'.van-switch--disabled': 1
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('listen to change event', (done) => {
|
||||
wrapper = mount(SwitchCell, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
value: false
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.vm.$on('input', (value) => {
|
||||
wrapper.vm.value = value;
|
||||
});
|
||||
|
||||
wrapper.vm.$on('change', (value) => {
|
||||
expect(value).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
const switchEl = wrapper.find('.van-switch')[0];
|
||||
switchEl.trigger('click');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user