Skip to content

Instantly share code, notes, and snippets.

@kuroski
Last active September 7, 2018 20:28
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/338d5f5ac02f91bed3329d2057ea587b to your computer and use it in GitHub Desktop.
Save kuroski/338d5f5ac02f91bed3329d2057ea587b to your computer and use it in GitHub Desktop.
jest.mock('@/store/actions')
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import UserView from '@/views/UserView'
import VUserSearchForm from '@/components/VUserSearchForm'
import VUserProfile from '@/components/VUserProfile'
import initialState from '@/store/state'
import actions from '@/store/actions'
import userFixture from './fixtures/user'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('UserView', () => {
let state
const build = () => {
const wrapper = shallowMount(UserView, {
localVue,
store: new Vuex.Store({
state,
actions,
})
})
return {
wrapper,
userSearchForm: () => wrapper.find(VUserSearchForm),
userProfile: () => wrapper.find(VUserProfile)
}
}
beforeEach(() => {
jest.resetAllMocks()
state = { ...initialState }
})
...
...
it('searches for a user when received "submitted"', () => {
// arrange
const expectedUser = 'kuroski'
const { userSearchForm } = build()
// act
userSearchForm().vm.$emit('submitted', expectedUser)
// assert
expect(actions.SEARCH_USER).toHaveBeenCalled()
expect(actions.SEARCH_USER.mock.calls[0][1]).toEqual({ username: expectedUser })
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment