Skip to content

Instantly share code, notes, and snippets.

@kuroski
Created September 7, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuroski/fed5c5aba4e525f0ecf53604f7950545 to your computer and use it in GitHub Desktop.
Save kuroski/fed5c5aba4e525f0ecf53604f7950545 to your computer and use it in GitHub Desktop.
import { shallowMount } from '@vue/test-utils'
import VUserSearchForm from '@/components/VUserSearchForm'
describe('VUserSearchForm', () => {
const build = () => {
const wrapper = shallowMount(VUserSearchForm)
return {
wrapper,
input: () => wrapper.find('input'),
button: () => wrapper.find('button'),
}
}
it('renders the component', () => {
// arrange
const { wrapper } = build()
// assert
expect(wrapper.html()).toMatchSnapshot()
})
it('renders main child components', () => {
// arrange
const { input, button } = build()
// assert
expect(input().exists()).toBe(true)
expect(button().exists()).toBe(true)
})
it('calls "submitted" event when submitting form', () => {
// arrange
const expectedUser = 'kuroski'
const { wrapper, button, input } = build()
input().element.value = expectedUser
// act
input().trigger('input')
button().trigger('click')
button().trigger('submit')
// assert
expect(wrapper.emitted().submitted[0]).toEqual([expectedUser])
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment