Last active
March 26, 2021 08:52
-
-
Save visualjerk/24522562fc503d65e88db592f569d8d7 to your computer and use it in GitHub Desktop.
Testing Vue 3 Components - LoginForm.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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