Skip to content

Commit 41808ab

Browse files
authored
build: fix test for signal option so it works across Node.js versions (#509)
1 parent 39d8b11 commit 41808ab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: test/request.test.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
578578
it("options.request.signal is passed as option to fetch", function () {
579579
return request("/", {
580580
request: {
581+
// We pass a value that is not an `AbortSignal`, and expect `fetch` to
582+
// throw an exception complaining about the value
581583
signal: "funk",
582584
},
583585
})
@@ -586,8 +588,13 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
586588
})
587589

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

0 commit comments

Comments
 (0)