В настоящее время я справляюсь с тестированием в Vuex.У меня есть следующее действие:
import { fetchProfile } from '../api'
export const getProfile = ({ commit }) => {
return fetchProfile()
.then(async (profile) => {
await commit(types.SET_AUTHENTICATED, true)
await commit(types.SET_PROFILE, profile.user)
})
}
И затем следующий тест:
jest.mock('../../src/api')
describe('task actions', () => {
it('fetchProfile commits user profile returned by api', async () => {
const profile = { first_name: 'John', last_name: 'Doe' }
fetchProfile.mockResolvedValue(profile)
const commit = jest.fn()
await actions.getProfile({ commit })
expect(commit).toHaveBeenCalledWith(types.SET_AUTHENTICATED, true)
expect(commit).toHaveBeenCalledWith('SET_PROFILE', profile)
})
})
Это не удается с
«SET_PROFILE» в качестве аргумента 1, ноон был вызван с помощью SET_AUTHENTICATED.
Если я закомментирую второе ожидание, тест пройден.
Однако, как я могу проверить, что оба коммита произошли правильно?Любая помощь или руководство будет высоко ценится
Спасибо.