jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
881 stars 116 forks source link

Odd slash behaviour with Request object #208

Open grug opened 2 years ago

grug commented 2 years ago

Hi there,

This might be a silly question, but I'd like to get to the bottom of it.

When I'm not using this library and I have the following code/test:

    it("should generate the correct request to be sent to the proxy server", () => {
      const request = new Request("https://foo.com");

      expect(request.url).toEqual("https://foo.com");
    });

It passes.

When I start using jest-fetch-mock (set up as per the installation guide) and I run the identical code, I get this failure:

Expected: "https://foo.com"
    Received: "https://foo.com/"

Is there a reason the slash it added at the end? Unfortunately I have a more complex use case that means that this adding of a slash is problematic and isn't simply a case of "just adding the slash to my request object instantiation".

grug commented 2 years ago

I've just seen the readme:

Note: the request "url" is parsed and then printed using the equivalent of new URL(input).href so it may not match exactly with the URL's passed to fetch if they are not fully qualified. For example, passing "http://foo.com" to fetch will result in the request URL being "http://foo.com/" (note the trailing slash).

Is there any way to control this behaviour?