Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { mount, createLocalVue } from '@vue/test-utils'
- import config from '@/components/config'
- import axios from '@/axios-auth'
- import mockAxios from 'jest-mock-axios'
- const localVue = createLocalVue()
- const $rota = {
- path: '/tour'
- }
- describe('config', () => {
- const spy = jest.fn()
- afterEach(() => {
- mockAxios.reset()
- })
- it('call mounted hook', () => {
- const wrapper = mount(config, {
- localVue
- })
- wrapper.vm.mounted = spy
- expect(spy).toBeTruthy()
- })
- it('mocking axios request', (done) => {
- const wrapper = mount(config, {
- localVue,
- router,
- mocks: {
- $rota
- }
- })
- const catchFn = jest.fn()
- const thenFn = jest.fn()
- wrapper.vm.config()
- expect(mockAxios.post).toHaveBeenCalledWith('/users/config')
- const responseObj = {
- success: true,
- message: 'Configuração realizada!'
- }
- mockAxios.mockResponse(responseObj)
- expect(catchFn).not.toHaveBeenCalled()
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement