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> <script>
import Popup from 'src/mixins/popup'; import Popup from 'src/mixins/popup';
export default { export default {
name: 'van-popup', name: 'van-popup',

View File

@ -18,6 +18,18 @@ describe('Field', () => {
expect(wrapper.hasClass('van-field')).to.be.true; 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) => { it('create a text field with initialize value', (done) => {
wrapper = mount(Field, { wrapper = mount(Field, {
propsData: { propsData: {

View File

@ -2,6 +2,8 @@ import Picker from 'packages/picker';
import PickerColumn from 'packages/picker/src/picker-column'; import PickerColumn from 'packages/picker/src/picker-column';
import { mount } from 'avoriaz'; import { mount } from 'avoriaz';
const itemHeight = 44;
const pickerColumns = [ const pickerColumns = [
{ {
values: ['vip', 'normal'], values: ['vip', 'normal'],
@ -163,6 +165,9 @@ describe('PickerColumn', () => {
expect(wrapper.hasClass('van-picker-column')).to.be.true; expect(wrapper.hasClass('van-picker-column')).to.be.true;
expect(wrapper.vm.values.length).to.equal(0); 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) => { 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, { wrapper = mount(PickerColumn, {
propsData: { propsData: {
values: [1, 2] values: [1, 2, 3, 4, 5]
} }
}); });
expect(wrapper.vm.values.length).to.equal(2); expect(wrapper.vm.values.length).to.equal(5);
wrapper.vm.currentValues = [2, 3]; expect(wrapper.vm.value2Translate(2)).to.equal((1- Math.floor(5 / 2)) * (-itemHeight));
wrapper.update(); expect(wrapper.vm.translate2Value(0)).to.equal(3);
wrapper.vm.$nextTick(() => {
expect(wrapper.vm.values.length).to.equal(2);
expect(wrapper.vm.currentValue).to.equal(2);
done();
});
}); });
}); });

View File

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