5

I'm using Jest and axios-mock-adapter to write tests for my API services. The problem is that when I run the test I get an error stating:

Error: unable to verify the first certificate.

app.service.js is the following

import ApiService from '@/services/api.service'

export default {
  async loadDashboard (psRef) {
    let result = await ApiService.get('user/' + psRef + '/dashboard')
      .catch(error => {
        console.error(error)
      })
    return result.data
  }
}

api.service.js is where I create my axios instance like so

import Axios from 'axios'

const baseDomain = process.env.VUE_APP_BACKEND
const baseURL = `${baseDomain}${process.env.VUE_APP_API}`

export default Axios.create({
  baseURL: baseURL,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
})

The test is the following:

const baseDomain = process.env.VUE_APP_BACKEND
const baseURL = `${baseDomain}${process.env.VUE_APP_API}`

test('loadDashboard should return the dashboard data for the user', async () => {
  mock.onGet(`${baseURL}user/85/dashboard`).reply(200, { dashBoardData })

  let response = await AppService.loadDashboard(85)
  expect(response).toEqual(dashBoardData)

  // AppService.loadDashboard(85).then(response => {
  //   expect(response.data).toEqual(dashBoardData)
  // })
})

Does anybody know how to fix this error?

bba278
  • 399
  • 3
  • 18
  • Perhaps related? I am also getting this error with axios while running tests, but _am not_ using `axios-mock-adapter` I've added the cert to my trusted root store in windows and all passes when running the application. It's only while testing that I receive this error. Sorry to hijack your issue if it's unrelated :) – phillyslick Jan 06 '20 at 20:06
  • 1
    @phillyslick Well then it's not about what mock we are using but something else. I'm still getting the error but have parked it for now since I could not find a solution. – bba278 Jan 07 '20 at 10:15

0 Answers0