mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
unit test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Vue from 'vue';
|
||||
import Field from 'packages/field';
|
||||
import { mount } from 'avoriaz';
|
||||
|
||||
@@ -7,11 +8,73 @@ describe('Field', () => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create', () => {
|
||||
it('create a text field', () => {
|
||||
wrapper = mount(Field, {
|
||||
propsData: {}
|
||||
});
|
||||
|
||||
expect(wrapper.hasClass('zan-field')).to.be.true;
|
||||
});
|
||||
|
||||
it('create a text field with initialize value', () => {
|
||||
wrapper = mount(Field, {
|
||||
propsData: {
|
||||
value: 'test'
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.hasClass('zan-field')).to.be.true;
|
||||
expect(wrapper.data().currentValue).to.equal('test');
|
||||
|
||||
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||
|
||||
wrapper.vm.value = 'test2';
|
||||
wrapper.update();
|
||||
Vue.nextTick(() => {
|
||||
expect(wrapper.data().currentValue).to.equal('test2');
|
||||
expect(eventStub.calledOnce).to.be.true;
|
||||
expect(eventStub.calledWith('input'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('emit a focus event', () => {
|
||||
wrapper = mount(Field, {
|
||||
propsData: {}
|
||||
});
|
||||
|
||||
const input = wrapper.find('.zan-field__control')[0];
|
||||
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||
|
||||
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();
|
||||
// Vue.nextTick(() => {
|
||||
// expect(wrapper.data().currentValue).to.equal('test');
|
||||
// done();
|
||||
// });
|
||||
});
|
||||
|
||||
it('create a textarea field', () => {
|
||||
wrapper = mount(Field, {
|
||||
propsData: {
|
||||
type: 'textarea',
|
||||
autosize: false
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user