badge unit test

This commit is contained in:
cookfront 2017-04-14 22:09:02 +08:00
parent d7c4c73edb
commit 52cb15a101
2 changed files with 39 additions and 29 deletions

View File

@ -0,0 +1,24 @@
<template>
<zan-badge-group>
<zan-badge title="热销榜" info="8" @click="onItemClick"></zan-badge>
<zan-badge title="手握寿司" info="199" @click="onItemClick"></zan-badge>
</zan-badge-group>
</template>
<script>
import Badge from 'packages/badge';
import BadgeGroup from 'packages/badge-group';
export default {
components: {
'zan-badge': Badge,
'zan-badge-group': BadgeGroup
},
methods: {
onItemClick() {
console.log('click');
}
}
};
</script>

View File

@ -1,14 +1,5 @@
import Vue from 'vue';
import Badge from 'packages/badge';
import BadgeGroup from 'packages/badge-group';
import { mount } from 'avoriaz';
Vue.component(Badge.name, Badge);
Vue.component(BadgeGroup.name, BadgeGroup);
const component = Vue.component({
});
import BadgeTestComponent from '../components/badge';
describe('BadgeGroup', () => {
let wrapper;
@ -17,27 +8,22 @@ describe('BadgeGroup', () => {
});
it('create a badge-group', () => {
wrapper = mount(BadgeGroup);
wrapper = mount(BadgeTestComponent);
expect(wrapper.hasClass('zan-badge-group')).to.be.true;
expect(wrapper.instance().activeKey).to.equal(0);
expect(wrapper.data().badges.length).to.equal(0);
expect(wrapper.vNode.child.activeKey).to.equal(0);
expect(wrapper.vNode.child.badges.length).to.equal(2);
});
it('emit a click event when click badge', () => {
wrapper = mount(BadgeTestComponent);
const badge = wrapper.find('.zan-badge')[0];
const eventStub = sinon.stub(badge.vNode.child, '$emit');
badge.simulate('click');
expect(eventStub.calledWith('click')).to.be.true;
});
});
describe('Badge', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('create a badge', () => {
wrapper = mount(Badge, {
propsData: {
title: 'test'
}
});
expect(wrapper.hasClass('zan-badge')).to.be.true;
});
});