{"size": 1655, "ext": "js", "max_stars_repo_path": "components/switch/__test__/Switch.spec.js", "max_stars_repo_name": "vinaypai/material-components-vue", "max_stars_repo_stars_event_min_datetime": "2017-10-19T12:47:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-02T11:44:35.000Z", "max_issues_repo_path": "components/switch/__test__/Switch.spec.js", "max_issues_repo_name": "vinaypai/material-components-vue", "max_issues_repo_issues_event_min_datetime": "2017-10-24T02:42:06.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-16T20:56:55.000Z", "max_forks_repo_path": "components/switch/__test__/Switch.spec.js", "max_forks_repo_name": "vinaypai/material-components-vue", "max_forks_repo_forks_event_min_datetime": "2017-11-20T03:13:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-02T10:21:15.000Z"}
{"max_stars_count": 370, "max_issues_count": 243, "max_forks_count": 74, "avg_line_length": 29.5535714286, "max_line_length": 72, "alphanum_fraction": 0.6513595166}
import { mount } from '@vue/test-utils'
import Switch from '../Switch.vue'

describe('Switch', () => {
  it('should mount', () => {
    const wrapper = mount(Switch)
    expect(wrapper.isVueInstance()).toBeTruthy()
    expect(wrapper.vm.$data.mdcSwitch).toBeDefined()
  })

  it('should render with no prop', () => {
    const wrapper = mount(Switch)
    expect(wrapper).toMatchSnapshot()
    expect(wrapper.classes()).toContain('mdc-switch')
    expect(wrapper.find('input').attributes('disabled')).toBeUndefined()
  })

  it('should render as disabled', () => {
    const wrapper = mount(Switch, {
      propsData: {
        disabled: true
      }
    })
    expect(wrapper).toMatchSnapshot()
    expect(wrapper.classes()).toContain('mdc-switch--disabled')
    expect(wrapper.find('input').attributes('disabled')).toBeDefined()
  })

  it('should render as checked', () => {
    const wrapper = mount(Switch, {
      propsData: {
        checked: true
      }
    })
    expect(wrapper).toMatchSnapshot()
    expect(wrapper.vm.$data.mdcSwitch.checked).toBeTruthy()
    expect(wrapper.find('input').element.checked).toBeTruthy()
  })

  it('should render and emit', () => {
    const wrapper = mount(Switch)

    const input = wrapper.find('input')

    input.setChecked()
    expect(wrapper.emitted().change).toBeTruthy()
    expect(wrapper.vm.$data.mdcSwitch.checked).toBeTruthy()
    expect(wrapper.find('input').element.checked).toBeTruthy()

    input.setChecked(false)
    expect(wrapper.emitted().change).toBeTruthy()
    expect(wrapper.vm.$data.mdcSwitch.checked).toBeFalsy()
    expect(wrapper.find('input').element.checked).toBeFalsy()
  })
})
