Giter Site home page Giter Site logo

Support handling XHRs? about msw HOT 7 CLOSED

mswjs avatar mswjs commented on April 28, 2024
Support handling XHRs?

from msw.

Comments (7)

kentcdodds avatar kentcdodds commented on April 28, 2024 1

Thank you!

from msw.

kettanaito avatar kettanaito commented on April 28, 2024

Hi, @kentcdodds. I believe you mean so that MSW could intercept the requests made via XHR in your client code?

In that case it comes down to the possibilities of Service Workers, yet I don't see a reason why XHR wouldn't be causing the fetch event in a Service Worker.

Could you please give me an example of expected usage?

from msw.

kentcdodds avatar kentcdodds commented on April 28, 2024

I basically would like to swap this for an XHR request and have that still be handled by the service worker without needing to change anything in my handlers.

from msw.

kettanaito avatar kettanaito commented on April 28, 2024

Hi, @kentcdodds. I see. I've added a basic XHR test scenario, could you please see if this is how you intend to use MSW?

https://github.com/open-draft/msw/pull/95/files#diff-ac6cb7531f89526b2d98c2180c99ecdbR18-R20

from msw.

kentcdodds avatar kentcdodds commented on April 28, 2024

Yup, that's exactly it 👍

from msw.

kentcdodds avatar kentcdodds commented on April 28, 2024

I take it that since the build passed that this "just works™️"? Super!

from msw.

kettanaito avatar kettanaito commented on April 28, 2024

Yes, you should be able to mock a XHR requests as-is. I'll add the integration test to the master to test regressions, if any. Feel free to reopen this if you encounter any unexpected behavior on the library's side when dealing with XHR. Thanks for bringing this topic.

from msw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.