unit test: picker (#20)

* pick unit test
This commit is contained in:
张敏 2017-04-26 17:06:02 +08:00 committed by GitHub
parent b4544ef1dc
commit e239b9937d
4 changed files with 24 additions and 13 deletions

View File

@ -8,7 +8,6 @@
<script>
import Popup from 'src/mixins/popup';
export default {
name: 'van-popup',

View File

@ -18,6 +18,18 @@ describe('Field', () => {
expect(wrapper.hasClass('van-field')).to.be.true;
});
it('create a border field', () => {
wrapper = mount(Field, {
propsData: {
type: 'text',
border: true
}
});
expect(wrapper.hasClass('van-field')).to.be.true;
expect(wrapper.hasClass('van-field--border')).to.be.true;
});
it('create a text field with initialize value', (done) => {
wrapper = mount(Field, {
propsData: {

View File

@ -2,6 +2,8 @@ import Picker from 'packages/picker';
import PickerColumn from 'packages/picker/src/picker-column';
import { mount } from 'avoriaz';
const itemHeight = 44;
const pickerColumns = [
{
values: ['vip', 'normal'],
@ -163,6 +165,9 @@ describe('PickerColumn', () => {
expect(wrapper.hasClass('van-picker-column')).to.be.true;
expect(wrapper.vm.values.length).to.equal(0);
expect(wrapper.vm.visibleContentHeight).to.equal(itemHeight * 5);
expect(wrapper.vm.dragRange[0]).to.equal(3 * itemHeight);
expect(wrapper.vm.dragRange[1]).to.equal(2 * itemHeight);
});
it('change picker-column values', (done) => {
@ -180,20 +185,15 @@ describe('PickerColumn', () => {
});
});
it('create a picker with values', (done) => {
it('create a picker test translate', () => {
wrapper = mount(PickerColumn, {
propsData: {
values: [1, 2]
values: [1, 2, 3, 4, 5]
}
});
expect(wrapper.vm.values.length).to.equal(2);
wrapper.vm.currentValues = [2, 3];
wrapper.update();
wrapper.vm.$nextTick(() => {
expect(wrapper.vm.values.length).to.equal(2);
expect(wrapper.vm.currentValue).to.equal(2);
done();
});
expect(wrapper.vm.values.length).to.equal(5);
expect(wrapper.vm.value2Translate(2)).to.equal((1- Math.floor(5 / 2)) * (-itemHeight));
expect(wrapper.vm.translate2Value(0)).to.equal(3);
});
});

View File

@ -1,6 +1,6 @@
import Switch from 'packages/switch';
import Vue from 'vue';
import ZanLoading from 'packages/loading';
import VanLoading from 'packages/loading';
import { mount } from 'avoriaz';
describe('Switch', () => {
@ -38,7 +38,7 @@ describe('Switch', () => {
loading: true
}
});
const loading = wrapper.find(ZanLoading)[0];
const loading = wrapper.find(VanLoading)[0];
expect(wrapper.hasClass('van-switch')).to.be.true;
expect(loading.isVueComponent).to.be.true;