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

100% Statements 35/35
100% Branches 0/0
100% Functions 12/12
100% Lines 35/35
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                         
import chai, {expect} from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
 
chai.use(sinonChai)
 
import {mount} from '@vue/test-utils'
import ControllCount from '../../src/controllCount/index'
 
describe('ControllCount', () => {
  it('存在.', () => {
    expect(ControllCount).to.be.ok
  })
  describe('props', () => {
    it('设置 count.', () => {
      const wrapper = mount(ControllCount, {
        propsData: {
          count: 2
        }
      })
      expect(wrapper.props('count')).to.eq(2)
    })
    it('默认 maxCount.', () => {
      const wrapper = mount(ControllCount)
      expect(wrapper.props('maxCount')).to.eq(10)
    })
    it('设置 maxCount.', () => {
      const wrapper = mount(ControllCount, {
        propsData: {
          maxCount: 5
        }
      })
      expect(wrapper.props('maxCount')).to.eq(5)
    })
  })
  it('点击 button 触发 update:count 事件', (done) => {
    const callback = sinon.fake()
    const wrapper = mount(ControllCount, {
      propsData: {
        count: 1,
        maxCount: 2
      },
      listeners: {
        'update:count': callback
      }
    })
    wrapper.find('.next').trigger('click')
    setTimeout(() => {
      expect(callback).to.have.been.calledWith(2)
      done()
    })
  })
  it('点击 prev btn 不触发 update:count 事件', (done) => {
    const callback = sinon.fake()
    const wrapper = mount(ControllCount, {
      propsData: {
        count: 1,
        maxCount: 4
      },
      listeners: {
        'update:count': callback
      }
    })
    wrapper.find('.prev').trigger('click')
    setTimeout(() => {
      expect(callback).to.not.been.called
      done()
    })
  })
  it('点击 next btn 不触发 update:count 事件', (done) => {
    const callback = sinon.fake()
    const wrapper = mount(ControllCount, {
      propsData: {
        count: 1,
        maxCount: 1
      },
      listeners: {
        'update:count': callback
      }
    })
    wrapper.find('.next').trigger('click')
    setTimeout(() => {
      expect(callback).to.not.been.called
      done()
    })
  })
})