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

Mix real requests with mock requests ? #79

Closed
jacksonkr opened this issue May 23, 2020 · 1 comment
Closed

Mix real requests with mock requests ? #79

jacksonkr opened this issue May 23, 2020 · 1 comment

Comments

@jacksonkr
Copy link

jacksonkr commented May 23, 2020

Scenario

During development I am using stubRequest to return mock data for api endpoints that I know are incomplete.

Problem

On urls where there is no stub request to intercept the fetch, the fetch still never goes through - almost like moxios is catching EVERYTHING that goes through axios and not just the urls that match one of the stub requests.

Question

How can I have SOME fetches (which match a stubRequest) return mock data while allowing other fetches (which don't match any stub requests) return real data?

code

        moxios.install();

        const stubs = {};
        //todo: make top three expressions pull from constants @jkr
        stubs["^navigationMock"] = navigationMock;
        stubs["^ancillaryMock"] = ancillaryMock;
        stubs["^pageMock"] = pageMock;
        stubs[constants.EVENT_CALENDAR_HREF] = eventCalendarMock;
        stubs[constants.STYLE_GUIDE_HREF] = styleGuideMock;

        for (const key in stubs) {
            const re = new RegExp(key);
            const mock = stubs[key];
            // console.log(key, re, stubs[key])
            moxios.stubRequest(re, {
                status: 200,
                response: mock
            });
        }
        // console.log(moxios);

        axios.create();
@jacksonkr jacksonkr changed the title Mix is real requests with mock requests ? Mix real requests with mock requests ? May 23, 2020
@jacksonkr
Copy link
Author

It seems like moxios isn't really suited for this so I'm looking to go with axios interceptor instead

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