mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
unit test
This commit is contained in:
parent
85fe17deaf
commit
0e824d1e7b
Binary file not shown.
@ -149,6 +149,16 @@ module.exports = {
|
|||||||
src: '联系人.svg',
|
src: '联系人.svg',
|
||||||
css: 'contact',
|
css: 'contact',
|
||||||
'correct_contour_direction': true
|
'correct_contour_direction': true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
keywords: ['wechat'],
|
||||||
|
src: '微信支付.svg',
|
||||||
|
css: 'wechat'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
keywords: ['alipay'],
|
||||||
|
src: '支付宝.svg',
|
||||||
|
css: 'alipay'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
import Checkbox from 'packages/checkbox';
|
import Checkbox from 'packages/checkbox';
|
||||||
|
import CheckboxGroup from 'packages/checkbox-group';
|
||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
|
|
||||||
describe('Checkbox', () => {
|
describe('Checkbox', () => {
|
||||||
@ -7,7 +9,7 @@ describe('Checkbox', () => {
|
|||||||
wrapper && wrapper.destroy();
|
wrapper && wrapper.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create', () => {
|
it('create a checkbox', () => {
|
||||||
wrapper = mount(Checkbox, {
|
wrapper = mount(Checkbox, {
|
||||||
propsData: {}
|
propsData: {}
|
||||||
});
|
});
|
||||||
@ -15,3 +17,36 @@ describe('Checkbox', () => {
|
|||||||
expect(wrapper.hasClass('zan-checkbox')).to.be.true;
|
expect(wrapper.hasClass('zan-checkbox')).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('CheckboxGroup', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('create a checkbox-group', () => {
|
||||||
|
wrapper = mount(CheckboxGroup, {
|
||||||
|
propsData: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.hasClass('zan-checkbox-group')).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('emit a change event', () => {
|
||||||
|
wrapper = mount(CheckboxGroup, {
|
||||||
|
propsData: {
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
import Field from 'packages/field';
|
import Field from 'packages/field';
|
||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
|
|
||||||
@ -7,11 +8,73 @@ describe('Field', () => {
|
|||||||
wrapper && wrapper.destroy();
|
wrapper && wrapper.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create', () => {
|
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', () => {
|
||||||
|
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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
42
test/unit/specs/popup.spec.js
Normal file
42
test/unit/specs/popup.spec.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
import Popup from 'packages/popup';
|
||||||
|
import { mount } from 'avoriaz';
|
||||||
|
|
||||||
|
describe('Popup', () => {
|
||||||
|
let wrapper;
|
||||||
|
afterEach(() => {
|
||||||
|
wrapper && wrapper.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('create a popup', () => {
|
||||||
|
wrapper = mount(Popup, {
|
||||||
|
propsData: {
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.hasClass('zan-popup')).to.be.true;
|
||||||
|
expect(wrapper.instance().currentTransition).to.equal('popup-slide-bottom');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('create a show popup', () => {
|
||||||
|
wrapper = mount(Popup, {
|
||||||
|
propsData: {
|
||||||
|
value: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user