GithubHelp home page GithubHelp logo

Comments (4)

kettanaito avatar kettanaito commented on June 11, 2024

Hi, @jlissner. Thanks for reporting this!

What would be the use case when the location object exists but doesn't have the href property set?

That sounds a lot like a broken environment then. In that case, the environment has to be fixed. The interceptor is correctly relying on the existing global location object, which must have the href property.

return new URL(url.toString(), location.href || undefined)

This won't work, sadly, because if url is relative and location.href is missing, like in your case, the URL constructor will throw anyway.

I will close this for now but would like to hear from you regarding my question above.

from interceptors.

jlissner avatar jlissner commented on June 11, 2024

For my example, it was a simple test of react component. The request was made to a fully qualified URL, so no base url had been set. I can try to set up a repo to reproduce, but it seems that you could repeat it fairly easily. The app was created with create-react-app, using axios to fetch the data (which if I set the adapter to http doesn't have this problem, but introduces other problems). Then, just create a simple test, having msw try to mock a response from say, http://example.com, and when you do const data = await axios({ url: 'http://example.com', method: 'GET' }); in your code, it will break.

from interceptors.

kettanaito avatar kettanaito commented on June 11, 2024

I can try to set up a repo to reproduce

Please do! I'd be happy to iterate on this together once the reproduction is here. Thanks.

from interceptors.

jlissner avatar jlissner commented on June 11, 2024

In working to reproduce, I found where the root of the issue was coming from :)

We needed to mock some window location methods, such as described in articles like https://remarkablemark.org/blog/2018/11/17/mock-window-location/

So, we ended up with a piece of code in our setup file that looked like this:

Object.defineProperty(global, 'location', {
  value: {
    assign: jest.fn(),
    reload: jest.fn(),
    href: '', // this was the problem
  },
  writable: true,
});

I agree that this SHOULDN'T happen, and I will have to dig further to understand why it happened in the first place as no including it at all works just fine, but still took hours to understand the error being given: Invalid base URL, considering now base URL was given.

from interceptors.

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.