Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import { mount, createLocalVue } from '@vue/test-utils'
  2. import config from '@/components/config'
  3. import axios from '@/axios-auth'
  4. import mockAxios from 'jest-mock-axios'
  5.  
  6. const localVue = createLocalVue()
  7.  
  8. const $rota = {
  9. path: '/tour'
  10. }
  11.  
  12. describe('config', () => {
  13. const spy = jest.fn()
  14.  
  15. afterEach(() => {
  16. mockAxios.reset()
  17. })
  18.  
  19.  
  20. it('call mounted hook', () => {
  21. const wrapper = mount(config, {
  22. localVue
  23. })
  24. wrapper.vm.mounted = spy
  25. expect(spy).toBeTruthy()
  26. })
  27.  
  28. it('mocking axios request', (done) => {
  29. const wrapper = mount(config, {
  30. localVue,
  31. router,
  32. mocks: {
  33. $rota
  34. }
  35. })
  36. const catchFn = jest.fn()
  37. const thenFn = jest.fn()
  38.  
  39. wrapper.vm.config()
  40. expect(mockAxios.post).toHaveBeenCalledWith('/users/config')
  41.  
  42. const responseObj = {
  43. success: true,
  44. message: 'Configuração realizada!'
  45. }
  46.  
  47. mockAxios.mockResponse(responseObj)
  48. expect(catchFn).not.toHaveBeenCalled()
  49. })
  50. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement