field unit test

This commit is contained in:
cookfront 2017-04-17 14:47:15 +08:00
parent cd049aa2a1
commit e94edd480e
2 changed files with 49 additions and 52 deletions

View File

@ -16,9 +16,7 @@ export default {
},
methods: {
onItemClick() {
console.log('click');
}
onItemClick() {}
}
};
</script>

View File

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