[Improvement] add utils test cases (#380)

This commit is contained in:
neverland
2017-12-05 21:32:02 +08:00
committed by GitHub
parent 5a17bc520a
commit df835618b0
9 changed files with 191 additions and 67 deletions
+19 -9
View File
@@ -1,7 +1,6 @@
import Area from 'packages/area';
import { mount } from 'avoriaz';
import AreaList from '../mock/area.json';
import { setTimeout } from 'timers';
describe('Area', () => {
let wrapper;
@@ -27,8 +26,6 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
const confirmBtn = wrapper.find('.van-picker__confirm')[0];
const eventStub = sinon.stub(wrapper.vm, '$emit');
@@ -49,7 +46,6 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
expect(wrapper.vm.$refs.picker.getColumnValue(2).code).to.equal('110101');
wrapper.setProps({
@@ -68,9 +64,7 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
expect(wrapper.vm.areaColumns.length).to.equal(0);
});
it('create an area with columnsNum equal 2', () => {
@@ -81,7 +75,6 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
expect(wrapper.vm.areaColumns.length).to.equal(2);
});
@@ -93,7 +86,6 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
expect(wrapper.vm.areaColumns.length).to.equal(1);
});
@@ -104,7 +96,6 @@ describe('Area', () => {
}
});
expect(wrapper.hasClass('van-area')).to.be.true;
const cancelBtn = wrapper.find('.van-picker__cancel')[0];
const eventStub = sinon.stub(wrapper.vm, '$emit');
@@ -115,4 +106,23 @@ describe('Area', () => {
done();
});
});
it('onChange method', () => {
wrapper = mount(Area, {
propsData: {
areaList: AreaList
}
});
let list = [];
const setColumnValues = (index, arr) => {
list = [...list, ...arr];
};
const code = { code: '110101' };
wrapper.vm.onChange({ setColumnValues }, [code], 0);
wrapper.vm.onChange({ setColumnValues }, [code, code], 1);
expect(list.length).to.equal(33);
});
});