From 1af923e9d29903d7887d368440b29f36417156d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Tue, 5 Sep 2017 11:42:51 +0800 Subject: [PATCH] Field: add test cases --- test/unit/components/field.vue | 18 +++++++++++++++ test/unit/specs/field.spec.js | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/unit/components/field.vue diff --git a/test/unit/components/field.vue b/test/unit/components/field.vue new file mode 100644 index 000000000..581a0e88e --- /dev/null +++ b/test/unit/components/field.vue @@ -0,0 +1,18 @@ + + + + diff --git a/test/unit/specs/field.spec.js b/test/unit/specs/field.spec.js index 47e8a8b7d..9b38bf891 100644 --- a/test/unit/specs/field.spec.js +++ b/test/unit/specs/field.spec.js @@ -1,4 +1,5 @@ import Field from 'packages/field'; +import FieldWithIcon from '../components/field'; import { mount } from 'avoriaz'; describe('Field', () => { @@ -126,4 +127,43 @@ describe('Field', () => { done(); }, 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(); + }); });