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

100% Statements 20/20
100% Branches 0/0
100% Functions 6/6
100% Lines 20/20
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                                                                           
import chai, {expect} from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
 
chai.use(sinonChai)
import {mount} from '@vue/test-utils'
 
import AmRadio from '../../src/radio/index'
 
describe('AmCheckbox', () => {
  it('存在.', () => {
    expect(AmRadio).to.be.ok
  })
  it('设置 disabled', () => {
    const callback = sinon.fake()
    const wrapper = mount(AmRadio, {
      propsData: {
        model: true,
        disabled: true
      }
    })
    wrapper.trigger('click')
    expect(callback).to.not.have.been.called
  })
  it('设置 name', () => {
    const wrapper = mount(AmRadio, {
      propsData: {
        model: true,
        name: 'ha'
      }
    })
    expect(wrapper.props('name')).to.eq('ha')
  })
  it('设置 v-model 为布尔', () => {
    const wrapper = mount(AmRadio, {
      propsData: {
        model: true
      }
    })
    expect(wrapper.props('model')).to.eq(true)
  })
  it('设置 v-model 为字符串, 默认不选中', () => {
    const callback = sinon.fake()
    const wrapper = mount(AmRadio, {
      attachToDocument: true,
      propsData: {
        model: '',
        value: 'a'
      },
      listeners: {
        'change': callback
      }
    })
    wrapper.trigger('click')
    expect(callback).to.have.been.calledWith('a')
  })
})