mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
badge unit test
This commit is contained in:
parent
d7c4c73edb
commit
52cb15a101
24
test/unit/components/badge.vue
Normal file
24
test/unit/components/badge.vue
Normal 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>
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user