unit test

This commit is contained in:
cookfront 2017-04-13 15:56:37 +08:00
parent 7ae82872e1
commit dbb4341323

View File

@ -1,80 +1,80 @@
import Vue from 'vue'; // import Vue from 'vue';
import Field from 'packages/field'; // import Field from 'packages/field';
import { mount } from 'avoriaz'; // import { mount } from 'avoriaz';
describe('Field', () => { // describe('Field', () => {
let wrapper; // let wrapper;
afterEach(() => { // afterEach(() => {
wrapper && wrapper.destroy(); // wrapper && wrapper.destroy();
}); // });
it('create a text field', () => { // it('create a text field', () => {
wrapper = mount(Field, { // wrapper = mount(Field, {
propsData: {} // propsData: {}
}); // });
expect(wrapper.hasClass('zan-field')).to.be.true; // expect(wrapper.hasClass('zan-field')).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: {
value: 'test' // value: 'test'
} // }
}); // });
expect(wrapper.hasClass('zan-field')).to.be.true; // expect(wrapper.hasClass('zan-field')).to.be.true;
expect(wrapper.data().currentValue).to.equal('test'); // expect(wrapper.data().currentValue).to.equal('test');
const eventStub = sinon.stub(wrapper.vm, '$emit'); // const eventStub = sinon.stub(wrapper.vm, '$emit');
wrapper.vm.value = 'test2'; // wrapper.vm.value = 'test2';
wrapper.update(); // wrapper.update();
Vue.nextTick(() => { // Vue.nextTick(() => {
expect(wrapper.data().currentValue).to.equal('test2'); // expect(wrapper.data().currentValue).to.equal('test2');
expect(eventStub.calledOnce).to.be.true; // expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('input')); // expect(eventStub.calledWith('input'));
done(); // done();
}); // });
}); // });
it('emit a focus event', () => { // it('emit a focus event', () => {
wrapper = mount(Field, { // wrapper = mount(Field, {
propsData: {} // propsData: {}
}); // });
const input = wrapper.find('.zan-field__control')[0]; // const input = wrapper.find('.zan-field__control')[0];
const eventStub = sinon.stub(wrapper.vm, '$emit'); // const eventStub = sinon.stub(wrapper.vm, '$emit');
input.simulate('focus'); // input.simulate('focus');
expect(eventStub.calledOnce).to.be.true; // expect(eventStub.calledOnce).to.be.true;
expect(eventStub.calledWith('focus')).to.be.true; // expect(eventStub.calledWith('focus')).to.be.true;
}); // });
it('input some value to filed', () => { // it('input some value to filed', () => {
// wrapper = mount(Field, { // // wrapper = mount(Field, {
// propsData: {} // // propsData: {}
// }); // // });
// const input = wrapper.find('.zan-field__control')[0]; // // const input = wrapper.find('.zan-field__control')[0];
// input.element.value = 'test'; // // input.element.value = 'test';
// wrapper.update(); // // wrapper.update();
// Vue.nextTick(() => { // // Vue.nextTick(() => {
// expect(wrapper.data().currentValue).to.equal('test'); // // expect(wrapper.data().currentValue).to.equal('test');
// done(); // // done();
// }); // // });
}); // });
it('create a textarea field', () => { // it('create a textarea field', () => {
wrapper = mount(Field, { // wrapper = mount(Field, {
propsData: { // propsData: {
type: 'textarea', // type: 'textarea',
autosize: false // autosize: false
} // }
}); // });
expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true; // expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true;
}); // });
}); // });