Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moxios.install() does not seem to install adapter #15

Closed
jomag opened this issue Dec 6, 2016 · 4 comments
Closed

moxios.install() does not seem to install adapter #15

jomag opened this issue Dec 6, 2016 · 4 comments

Comments

@jomag
Copy link

jomag commented Dec 6, 2016

Hi,

I'm trying to use moxios, but I find that the requests are performed as usual and moxios.requests.mostRecent() returns undefined.

It seems that moxios does not install any mock adapter.

Here's a minimal test:

import moxios from "moxios";
import axios from "axios";

describe("moxios", () => {
  it("mocks axios", () => {
    console.log("Adapter before: ");
    console.log(axios.defaults.adapter);
    moxios.install();
    console.log("Adapter after installing: ");
    console.log(axios.defaults.adapter);
    moxios.uninstall();
    console.log("Adapter after uninstalling: ");
    console.log(axios.defaults.adapter);
  });
});

Output:

Adapter before: 
[Function: httpAdapter]
Adapter after installing: 
[Function: httpAdapter]
Adapter after uninstalling: 
[Function: httpAdapter]

I run the test with this command:

node_modules/.bin/mocha --compilers js:babel-core/register moxios.js
@jomag
Copy link
Author

jomag commented Dec 6, 2016

I think I've found my error: if I change the install/uninstall calls to pass "axios" everything works. Not sure why though...

import moxios from "moxios";
import axios from "axios";

describe("moxios", () => {
  it("mocks axios", () => {
    console.log("Adapter before: ");
    console.log(axios.defaults.adapter);
    moxios.install(axios);
    console.log("Adapter after installing: ");
    console.log(axios.defaults.adapter);
    moxios.uninstall(axios);
    console.log("Adapter after uninstalling: ");
    console.log(axios.defaults.adapter);
  });
});

Looking at the moxios code it seems that it should not be necessary...

@lucantini
Copy link

I had the exact same problem. I just updated my axios version to the 0.15.3 and it worked just fine, even without passing axios to the call of moxios.install

@mzabriskie
Copy link
Member

If moxios is using the same version of axios as your app, you shouldn't need to pass axios to moxios.install. If you are using different versions, or you are using a custom instance, then passing an instance is required.

@leon-yum
Copy link

leon-yum commented Mar 21, 2018

Hi this is still a problem for me, and doing moxios.install(axios) did not fix things :( https://stackoverflow.com/questions/49414373/moxios-typeerror-cannot-read-property-adapter-of-undefined

"axios": "^0.16.2",
"moxios": "^0.4.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants