From 5c389968f7c4651de0d72bd426009d747893a5ba Mon Sep 17 00:00:00 2001 From: cookfront Date: Wed, 12 Apr 2017 15:01:45 +0800 Subject: [PATCH] unit test --- packages/icon/src/icon.vue | 5 ++++- test/unit/specs/badge.spec.js | 25 +++++++++++++++++++++++ test/unit/specs/cell.spec.js | 37 ++++++++++++++++++++++++++++++++++- test/unit/specs/icon.spec.js | 35 +++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 test/unit/specs/badge.spec.js create mode 100644 test/unit/specs/icon.spec.js diff --git a/packages/icon/src/icon.vue b/packages/icon/src/icon.vue index 29b7caa8a..cb4cc92e3 100644 --- a/packages/icon/src/icon.vue +++ b/packages/icon/src/icon.vue @@ -7,7 +7,10 @@ name: 'zan-icon', props: { - name: String + name: { + type: String, + required: true + } }, methods: { diff --git a/test/unit/specs/badge.spec.js b/test/unit/specs/badge.spec.js new file mode 100644 index 000000000..956cec2a5 --- /dev/null +++ b/test/unit/specs/badge.spec.js @@ -0,0 +1,25 @@ +import Badge from 'packages/badge'; +import BadgeGroup from 'packages/badge-group'; +import { mount } from 'avoriaz'; + +describe('Badge', () => { + let wrapper; + afterEach(() => { + wrapper && wrapper.destroy(); + }); +}); + +describe('BadgeGroup', () => { + let wrapper; + afterEach(() => { + wrapper && wrapper.destroy(); + }); + + it('create a badge-group', () => { + wrapper = mount(BadgeGroup); + + expect(wrapper.hasClass('zan-badge-group')).to.be.true; + expect(wrapper.instance().activeKey).to.equal(0); + expect(wrapper.data().badges.length).to.equal(0); + }); +}); diff --git a/test/unit/specs/cell.spec.js b/test/unit/specs/cell.spec.js index 5699c3910..2324f806c 100644 --- a/test/unit/specs/cell.spec.js +++ b/test/unit/specs/cell.spec.js @@ -1,4 +1,5 @@ import CellGroup from 'packages/cell-group'; +import Cell from 'packages/cell'; import { mount } from 'avoriaz'; describe('CellGroup', () => { @@ -7,7 +8,7 @@ describe('CellGroup', () => { wrapper && wrapper.destroy(); }); - it('create', () => { + it('create a cell-group', () => { wrapper = mount(CellGroup, { propsData: {} }); @@ -15,3 +16,37 @@ describe('CellGroup', () => { expect(wrapper.hasClass('zan-cell-group')).to.be.true; }); }); + +describe('Cell', () => { + let wrapper; + afterEach(() => { + wrapper && wrapper.destroy(); + }); + + it('create', () => { + wrapper = mount(Cell); + + expect(wrapper.hasClass('zan-cell')).to.be.true; + }); + + it('create a required cell', () => { + wrapper = mount(Cell, { + propsData: { + required: true + } + }); + + expect(wrapper.hasClass('zan-cell')).to.be.true; + expect(wrapper.hasClass('zan-cell--required')).to.be.true; + }); + + it('emit a click event', () => { + wrapper = mount(Cell); + + const eventStub = sinon.stub(wrapper.vm, '$emit'); + wrapper.simulate('click'); + + expect(eventStub.calledOnce).to.be.true; + expect(eventStub.calledWith('click')).to.be.true; + }); +}); diff --git a/test/unit/specs/icon.spec.js b/test/unit/specs/icon.spec.js new file mode 100644 index 000000000..e479e3614 --- /dev/null +++ b/test/unit/specs/icon.spec.js @@ -0,0 +1,35 @@ +import Icon from 'packages/icon'; +import { mount } from 'avoriaz'; + +describe('Icon', () => { + let wrapper; + + afterEach(() => { + wrapper && wrapper.destroy(); + }); + + it('create a icon', () => { + wrapper = mount(Icon, { + propsData: { + name: 'arrow' + } + }); + + expect(wrapper.hasClass('zan-icon')).to.be.true; + expect(wrapper.hasClass('zan-icon-arrow')).to.be.true; + }); + + it('emit a click event', () => { + wrapper = mount(Icon, { + propsData: { + name: 'arrow' + } + }); + + const eventStub = sinon.stub(wrapper.vm, '$emit'); + wrapper.simulate('click'); + + expect(eventStub.calledOnce).to.be.true; + expect(eventStub.calledWith('click')).to.be.true; + }); +});