mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
35 lines
849 B
JavaScript
35 lines
849 B
JavaScript
import { shallowMount } from '@vue/test-utils'
|
|
import Btn from './Btn'
|
|
|
|
const factory = () => shallowMount(Btn, {
|
|
propsData: {
|
|
label: 'click me!'
|
|
}
|
|
})
|
|
|
|
describe('Btn', () => {
|
|
test('mounts properly', () => {
|
|
const wrapper = factory()
|
|
expect(wrapper.vm).toBeTruthy()
|
|
})
|
|
|
|
test('renders properly', () => {
|
|
const wrapper = factory()
|
|
expect(wrapper.html()).toMatchSnapshot()
|
|
})
|
|
|
|
test('calls handleClick on click', () => {
|
|
const handleClickMock = jest.spyOn(Btn.methods, 'handleClick')
|
|
const wrapper = factory()
|
|
wrapper.find('button').trigger('click')
|
|
expect(handleClickMock).toHaveBeenCalled()
|
|
handleClickMock.mockRestore()
|
|
})
|
|
|
|
test('clicked is true after click', () => {
|
|
const wrapper = factory()
|
|
wrapper.find('button').trigger('click')
|
|
expect(wrapper.vm.clicked).toBe(true)
|
|
})
|
|
})
|