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

Bug: moxios.wait doesn't call axios promise if the axios call being tested passes params into it #97

Open
AmasaDelano opened this issue Sep 29, 2022 · 0 comments

Comments

@AmasaDelano
Copy link

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! :)

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

1 participant