All files / switch/__tests__ Switch-test.js

100% Statements 20/20
100% Branches 0/0
66.67% Functions 6/9
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    1x 1x 1x 1x   1x 1x 1x 1x     1x 1x 1x     1x 1x 1x     1x 1x 1x 1x   1x 1x              
/* global it, describe */
 
import assert from 'assert'
import React from 'react'
import Switch from '../'
import {mount} from 'enzyme'
 
describe('Switch', () => {
  it('should be off by default', () => {
    const wrapper = mount(<Switch name='' onChange={() => {}} />)
    assert.equal(wrapper.find('.Switch-input').props().checked, false)
  })
 
  it('should be able to set to checked', () => {
    const wrapper = mount(<Switch name='' checked onChange={() => {}} />)
    assert(wrapper.find('.Switch-input').props().checked)
  })
 
  it('should be able to be set to disabled', () => {
    const wrapper = mount(<Switch name='' disabled onChange={() => {}} />)
    assert(wrapper.find('.Switch-input').props().disabled)
  })
 
  it('should allow toggle on/off', (done) => {
    const callback = (event) => {
      assert(event.target.checked)
      done()
    }
    const wrapper = mount(<Switch name='' onChange={callback} />)
    wrapper.find('.Switch-input').simulate('change', {
      target: {
        checked: true
      }
    })
  })
})