mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 15:09:16 +08:00
Field: add test cases
This commit is contained in:
parent
65b21b0710
commit
1af923e9d2
18
test/unit/components/field.vue
Normal file
18
test/unit/components/field.vue
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<template>
|
||||||
|
<van-field :onIconClick="onIconClick" @blur="$emit('blur')">
|
||||||
|
<div slot="icon">icon</div>
|
||||||
|
</van-field>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Field from 'packages/field';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
[Field.name]: Field
|
||||||
|
},
|
||||||
|
|
||||||
|
props: ['onIconClick']
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
import Field from 'packages/field';
|
import Field from 'packages/field';
|
||||||
|
import FieldWithIcon from '../components/field';
|
||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
|
|
||||||
describe('Field', () => {
|
describe('Field', () => {
|
||||||
@ -126,4 +127,43 @@ describe('Field', () => {
|
|||||||
done();
|
done();
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('show icon when has value and icon props', () => {
|
||||||
|
wrapper = mount(Field, {
|
||||||
|
propsData: {
|
||||||
|
icon: 'name',
|
||||||
|
value: '123'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-field__icon').length).to.equal(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('create a field with icon slot', () => {
|
||||||
|
const fn = sinon.spy();
|
||||||
|
|
||||||
|
wrapper = mount(FieldWithIcon, {
|
||||||
|
propsData: {
|
||||||
|
onIconClick: fn
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.find('.van-field__icon')[0].trigger('click');
|
||||||
|
expect(fn.calledOnce).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('blur event', (done) => {
|
||||||
|
const blur = sinon.spy();
|
||||||
|
const clickIcon = sinon.spy();
|
||||||
|
|
||||||
|
wrapper = mount(FieldWithIcon, {});
|
||||||
|
wrapper.vm.$on('blur', blur);
|
||||||
|
|
||||||
|
wrapper.find('.van-field__icon')[0].trigger('click');
|
||||||
|
wrapper.find('.van-field__control')[0].trigger('blur');
|
||||||
|
|
||||||
|
expect(blur.calledOnce).to.be.true;
|
||||||
|
expect(clickIcon.calledOnce).to.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user