all files / tests/unit/ nav.spec.js

100% Statements 19/19
100% Branches 0/0
100% Functions 6/6
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                               
import chai, { expect } from "chai";
import Vue from 'vue'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
chai.use(sinonChai)
import { shallowMount, mount } from "@vue/test-utils"
import Nav from "@/nav/nav.vue";
import NavItem from "@/nav/nav-item"
 
describe("Nav.vue", () => {
    it('存在.', () => {
        expect(Nav).to.exist
    })
 
    it('value是几就选中第几个', (done) => {
        Vue.component('GNavItem', NavItem)
        const wrapper = mount(Nav, {
            slots: {
                default:`
                    <g-nav-item name="home">处理中心</g-nav-item>
                    <g-nav-item name="zhaopin">招聘</g-nav-item>
                    <g-nav-item name="weixin">微信</g-nav-item>
                `
            },
            propsData: {
                value: 'zhaopin'
            }
        })
        setTimeout(() => {
            expect(wrapper.find('.active').text()).to.be.eq('招聘')
            done()
        })
    })
 
    it('触发input事件', (done) => {
        const callback = sinon.fake()
        Vue.component('GNavItem', NavItem)
        const wrapper = mount(Nav, {
            slots: {
                default:`
                    <g-nav-item name="home">处理中心</g-nav-item>
                    <g-nav-item name="zhaopin">招聘</g-nav-item>
                    <g-nav-item name="weixin">微信</g-nav-item>
                `
            },
            listeners: {
                'input': callback
            }
        })
        wrapper.find('[data-name="weixin"]').trigger('click')
        setTimeout(() => {
            expect(callback).to.have.been.called
            expect(callback).to.have.been.calledWith('weixin')
            done()
        })
    })
 
});