Skip to content

Instantly share code, notes, and snippets.

@visualjerk
Last active March 26, 2021 08:52
Show Gist options
  • Save visualjerk/24522562fc503d65e88db592f569d8d7 to your computer and use it in GitHub Desktop.
Save visualjerk/24522562fc503d65e88db592f569d8d7 to your computer and use it in GitHub Desktop.
Testing Vue 3 Components - LoginForm.spec.js
import { mount } from '@vue/test-utils'
import LoginForm from './LoginForm.vue'
describe('LoginForm', () => {
it('does not submit empty form', () => {
const wrapper = mount(LoginForm)
const form = wrapper.find('form')
form.trigger('submit')
expect(wrapper.emitted('submit')).toBeUndefined()
})
it('submits form when data is filled', () => {
const wrapper = mount(LoginForm)
const FORM_DATA = {
username: 'yoda',
password: '4force',
}
wrapper.setData({
formData: FORM_DATA,
})
const form = wrapper.find('form')
form.trigger('submit')
expect(wrapper.emitted('submit')).toBeDefined()
expect(wrapper.emitted('submit')[0][0]).toMatchObject(FORM_DATA)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment