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

94.74% Statements 18/19
100% Branches 0/0
80% Functions 4/5
94.74% Lines 18/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                                                                 
import chai, {expect} from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
 
chai.use(sinonChai)
 
import {mount} from '@vue/test-utils'
 
import Vue from 'vue'
import AmSelect from '../../src/select/index'
import AmOption from '../../src/select/option'
 
Vue.component('am-select', AmSelect)
Vue.component('am-option', AmOption)
 
describe('AmOption', () => {
  it('存在.', () => {
    expect(AmOption).to.be.ok
  })
  it('设置 disabled', (done) => {
    const Component = {
      inject: ['root'],
      template: `
        <am-select>
          <am-option value="A" disabled>Apple</am-option>
          <am-option value="B">Banana</am-option>
          <am-option value="C">Cherry</am-option>
        </am-select>
        `
    }
    const wrapper = mount(Component, {
      provide: {
        root() {
          return {root: this}
        }
      },
    })
    wrapper.find('.am-select').trigger('click')
    setTimeout(() => {
      const el = wrapper.find('[data-name="A"]')
      expect(el.classes('disabled')).to.eq(true);
 
      const callback = sinon.fake()
      wrapper.vm.$on('update:selected', callback)
      el.trigger('click')
      expect(callback).to.not.have.been.called
      done()
    })
  })
})