nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 245 forks source link

axios undefinded in nuxt +jest unit testing #416

Closed vipulphysiofirst closed 3 years ago

vipulphysiofirst commented 4 years ago

I am using nuxt + jest for uniit testing , when id testing a page it has axios call in method like this
IN pay.vue

async pay(){
   try{
     var respone  = this.$axios.get('API_URL_HERE);
     this.fee = response.data;
   } catch(e){
      console.log(e)
   }
 }

and test file pay.spec.js

import { mount } from '@vue/test-utils';
import paynow from '../pages/pay';
import   axios from "axios";
import Vue from 'vue'

jest.mock("axios", () => ({
  get: () => Promise.resolve({ data: [{ val: 1 }] })
}));

describe("paynow.vue", () => {
  it("mocking the axios call to get posts should work", async () => {
    var wrapper = mount(paynow);
    wrapper.vm.pay() 
  });
});

But i am getting this error after running it. TypeError: Cannot read property 'get' of undefined axios is injected inplugin then why it is showing undefined

BartzLeon commented 4 years ago

This seems to be a duplicate of: https://github.com/nuxt-community/axios-module/issues/105

farnabaz commented 3 years ago

Closed because duplicate.