Nuxt/examples/jest-vtu-example/components/Btn/Btn.spec.js
Paul Gascou-Vaillancourt 5c0d12fb13 chore(examples): Add Jest + Vue Test Utils example (#4116)
* chore(examples): Add Jest + Vue Test Utils example

* style: Lint

* refactor: Rename button component & fix lint errors

* refactor: Use export default

* refactor: Babel 7 setup
2018-10-25 19:42:21 +02:00

37 lines
866 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.isVueInstance()).toBeTruthy()
})
test('renders properly', () => {
const wrapper = factory()
expect(wrapper.html()).toMatchSnapshot()
})
test('calls handleClick on click', () => {
const wrapper = factory()
const handleClickMock = jest.fn()
wrapper.setMethods({
handleClick: handleClickMock
})
wrapper.find('button').trigger('click')
expect(handleClickMock).toHaveBeenCalled()
})
test('clicked is true after click', () => {
const wrapper = factory()
wrapper.find('button').trigger('click')
expect(wrapper.vm.clicked).toBe(true)
})
})