jonnydgreen / deno-mock-fetch

Deno mock fetch implementation
MIT License
8 stars 0 forks source link

Query matching fails sometimes #9

Open hermann-p opened 1 day ago

hermann-p commented 1 day ago

Request-URL with more complex query parameters won't match.

const url = "https://address-wont-matt.er/things?foo=a,b,c";
mockFetch.intercept(url).response("well done");
const result = await fetch(url)
  .then(res => res.ok ? res.body() : Promise.reject(res.text));
assertEquals(result, "well done");

This will result in an error, no matching mock found for <the url>.

The original URL I needed was much longer and more complex (YouTrack API filters), but I could narrowing it down to the commas as minimal error cause.
Removing the commas from the query works (but that won't suffice my testing requirements).

As a workaround I passed a regex instead of a string to the .intercept method and it worked just fine, but this should not be necessary.

jonnydgreen commented 1 day ago

Interesting! Thanks for reporting! :) Would you be interested in contributing a PR to address this?

hermann-p commented 1 day ago

I'll take a look, but it's going to take a little till I find some time.

jonnydgreen commented 23 hours ago

Awesome! No rush at all :)