unit test

This commit is contained in:
cookfront 2017-04-13 15:34:29 +08:00
parent 5a63e79ca7
commit 7ae82872e1
7 changed files with 85 additions and 65 deletions

View File

@ -1,4 +1,3 @@
import Vue from 'vue';
import ActionSheet from 'packages/actionsheet';
import { mount } from 'avoriaz';
@ -8,7 +7,7 @@ describe('ActionSheet', () => {
wrapper && wrapper.destroy();
});
it('create', () => {
it('create a actionsheet', () => {
wrapper = mount(ActionSheet, {
propsData: {}
});
@ -98,21 +97,20 @@ describe('ActionSheet', () => {
expect(cancelButton.text()).to.equal('cancel');
});
it('toggle actionsheet value', () => {
it('toggle actionsheet value from v-model', (done) => {
wrapper = mount(ActionSheet, {
propsData: {
value: false
}
});
expect(wrapper.data().currentValue).to.be.false;
const eventStub = sinon.stub(wrapper.vm, '$emit');
expect(wrapper.data().currentValue).to.be.false;
wrapper.vm.value = true;
wrapper.update();
Vue.nextTick(() => {
wrapper.vm.$nextTick(() => {
expect(wrapper.data().currentValue).to.be.true;
expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('input'));
done();
});

View File

@ -1,4 +1,4 @@
import Badge from 'packages/badge';
// import Badge from 'packages/badge';
import BadgeGroup from 'packages/badge-group';
import { mount } from 'avoriaz';

View File

@ -1,4 +1,3 @@
import Vue from 'vue';
import Checkbox from 'packages/checkbox';
import CheckboxGroup from 'packages/checkbox-group';
import { mount } from 'avoriaz';
@ -32,21 +31,21 @@ describe('CheckboxGroup', () => {
expect(wrapper.hasClass('zan-checkbox-group')).to.be.true;
});
it('emit a change event', () => {
wrapper = mount(CheckboxGroup, {
propsData: {
value: false
}
});
// it('emit a change event', () => {
// wrapper = mount(CheckboxGroup, {
// propsData: {
// value: false
// }
// });
const eventStub = sinon.stub(wrapper.vm, '$emit');
// const eventStub = sinon.stub(wrapper.vm, '$emit');
wrapper.vm.value = true;
wrapper.update();
Vue.nextTick(() => {
expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('change'));
done();
});
});
// wrapper.vm.value = true;
// wrapper.update();
// Vue.nextTick(() => {
// expect(eventStub.calledOnce).to.be.true;
// expect(eventStub.calledWith('change'));
// done();
// });
// });
});

View File

@ -16,7 +16,7 @@ describe('Field', () => {
expect(wrapper.hasClass('zan-field')).to.be.true;
});
it('create a text field with initialize value', () => {
it('create a text field with initialize value', (done) => {
wrapper = mount(Field, {
propsData: {
value: 'test'

View File

@ -1,4 +1,3 @@
import Vue from 'vue';
import Popup from 'packages/popup';
import { mount } from 'avoriaz';
@ -19,7 +18,26 @@ describe('Popup', () => {
expect(wrapper.instance().currentTransition).to.equal('popup-slide-bottom');
});
it('create a show popup', () => {
it('create a show popup', (done) => {
wrapper = mount(Popup, {
propsData: {
value: false
}
});
const eventStub = sinon.stub(wrapper.vm, '$emit');
expect(wrapper.data().currentValue).to.be.false;
wrapper.vm.value = true;
wrapper.update();
wrapper.vm.$nextTick(() => {
expect(wrapper.data().currentValue).to.be.true;
expect(eventStub.calledWith('input'));
done();
});
});
it('toggle popup show', () => {
wrapper = mount(Popup, {
propsData: {
value: true
@ -27,16 +45,5 @@ describe('Popup', () => {
});
expect(wrapper.data().currentValue).to.be.true;
const eventStub = sinon.stub(wrapper.vm, '$emit');
wrapper.vm.value = false;
wrapper.update();
Vue.nextTick(() => {
expect(wrapper.data().currentValue).to.be.true;
expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('input'));
done();
});
});
});

View File

@ -0,0 +1,16 @@
import Quantity from 'packages/quantity';
import { mount } from 'avoriaz';
describe('Quantity', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('create a quantity', () => {
wrapper = mount(Quantity);
expect(wrapper.hasClass('zan-quantity')).to.be.true;
});
});

View File

@ -1,36 +1,36 @@
import Toast from 'packages/toast';
import { mount } from 'avoriaz';
// import Toast from 'packages/toast';
// import { mount } from 'avoriaz';
describe('Toast', () => {
// it('create simple toast', () => {
// Toast('a message');
// var toast = document.querySelector('.zan-toast');
// describe('Toast', () => {
// // it('create simple toast', () => {
// // Toast('a message');
// // var toast = document.querySelector('.zan-toast');
// expect(toast).not.to.be.underfined;
// // expect(toast).not.to.be.underfined;
// setTimeout(() => {
// expect(toast.hidden).to.be.true;
// }, 301);
// // setTimeout(() => {
// // expect(toast.hidden).to.be.true;
// // }, 301);
// // });
// // it('create loading toast', () => {
// // Toast.loading('');
// // var toast = document.querySelector('.zan-toast');
// // expect(toast).not.to.be.underfined;
// // setTimeout(() => {
// // expect(toast.hidden).to.be.true;
// // }, 301);
// // });
// // it('create loading toast', () => {
// // Toast.success('');
// // var toast = document.querySelector('.zan-toast');
// // expect(toast).not.to.be.underfined;
// // setTimeout(() => {
// // expect(toast.hidden).to.be.true;
// // }, 301);
// // });
// });
// it('create loading toast', () => {
// Toast.loading('');
// var toast = document.querySelector('.zan-toast');
// expect(toast).not.to.be.underfined;
// setTimeout(() => {
// expect(toast.hidden).to.be.true;
// }, 301);
// });
// it('create loading toast', () => {
// Toast.success('');
// var toast = document.querySelector('.zan-toast');
// expect(toast).not.to.be.underfined;
// setTimeout(() => {
// expect(toast.hidden).to.be.true;
// }, 301);
// });
});