moxios
moxios copied to clipboard
Bug: moxios.wait doesn't call axios promise if the axios call being tested passes params into it
Moxios version: 0.4.0 Axios version: 0.27.2
Issue: If a params object with any parameters is passed into an axios.get
call, the moxios.wait
function never causes the axios promise to execute.
I made a sample project to replicate the bug here: isolated_test_bug.zip There are two tests in the project: both of the tests should pass, but instead, one of them passes and one of them fails.
Here are the tests from the attached project above:
const axios = require("axios");
const moxios = require("moxios");
describe("moxios.wait", function () {
let counter;
beforeEach(function () {
moxios.install();
});
afterEach(function () {
moxios.uninstall();
});
function axiosTest(params) {
moxios.stubRequest("test.com", {
code: 200,
response: "hello world"
});
counter = 0;
axios.get("test.com", {
params: params
}).then(function () {
counter = 1;
});
}
// This test passes. Good!
it("should work with an empty params object", function (done) {
axiosTest({});
moxios.wait(function () {
expect(counter).toBe(1);
done();
});
});
// This test fails, but it should pass.
it("should work with a non-empty params object", function (done) {
axiosTest({
"hello": "world"
});
moxios.wait(function () {
expect(counter).toBe(1);
done();
});
});
});
I'm happy to share any other information that might be helpful. Thanks! :)