Skip to content

Instantly share code, notes, and snippets.

@kuroski
Created September 12, 2018 01:57
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/988ecc102a38b03a37f298623533c6e3 to your computer and use it in GitHub Desktop.
Save kuroski/988ecc102a38b03a37f298623533c6e3 to your computer and use it in GitHub Desktop.
import { shallowMount, mount, createLocalVue } from '@vue/test-utils'
import ElementUI from 'element-ui'
import VUserSearchForm from '@/components/VUserSearchForm'
const localVue = createLocalVue()
localVue.use(ElementUI)
describe('VUserSearchForm', () => {
const build = () => {
const options = { localVue }
const wrapper = shallowMount(VUserSearchForm, options)
const wrapperMounted = mount(VUserSearchForm, options)
return {
wrapper,
wrapperMounted,
input: () => wrapper.find('.search-form__input'),
inputMounted: () => wrapperMounted.find('input'),
button: () => wrapperMounted.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 { wrapperMounted, button, inputMounted } = build()
inputMounted().element.value = expectedUser
// act
inputMounted().trigger('input')
button().trigger('click')
button().trigger('submit')
// assert
expect(wrapperMounted.emitted().submitted[0]).toEqual([expectedUser])
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment