Skip to content

Instantly share code, notes, and snippets.

@kuroski
Last active September 8, 2018 21:12
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/2d3708e09f0ab6fdd24a6e2450e9a70b to your computer and use it in GitHub Desktop.
Save kuroski/2d3708e09f0ab6fdd24a6e2450e9a70b to your computer and use it in GitHub Desktop.
jest.mock('@/api')
import flushPromises from 'flush-promises'
import actions from '@/store/actions'
import api from '@/api'
import userFixture from './fixtures/user'
describe('store actions', () => {
let commit
beforeEach(() => {
commit = jest.fn()
})
it('searches for user', async () => {
// arrange
const expectedUser = 'kuroski'
// act
await actions.SEARCH_USER({ commit }, { username: expectedUser })
await flushPromises()
// assert
expect(api.searchUser).toHaveBeenCalledWith(expectedUser)
expect(commit).toHaveBeenCalledWith('SET_USER', userFixture)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment