Skip to content

Commit

Permalink
build: fix test for signal option so it works across Node.js versio…
Browse files Browse the repository at this point in the history
…ns (#509)
  • Loading branch information
timrogers committed Aug 15, 2022
1 parent 39d8b11 commit 41808ab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/request.test.ts
Expand Up @@ -578,6 +578,8 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
it("options.request.signal is passed as option to fetch", function () {
return request("/", {
request: {
// We pass a value that is not an `AbortSignal`, and expect `fetch` to
// throw an exception complaining about the value
signal: "funk",
},
})
Expand All @@ -586,8 +588,13 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
})

.catch((error) => {
expect(error.message).toMatch(/\bsignal\b/i);
expect(error.message).toMatch(/\bAbortSignal\b/i);
// We can't match on the entire string because the message differs between
// Node versions.
//
// In v14 and v16, the message just mentions "signal" and has `instanceof`
// as one word, whereas in v18 it contains the stringified signal and uses
// proper English ("instance of").
expect(error.message).toMatch(/to be an instance ?of AbortSignal/);
});
});

Expand Down

0 comments on commit 41808ab

Please sign in to comment.