From 41808ab29f6a334cee084da60a1642e7347ad8c5 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Mon, 15 Aug 2022 14:28:54 +0100 Subject: [PATCH] build: fix test for `signal` option so it works across Node.js versions (#509) --- test/request.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/request.test.ts b/test/request.test.ts index 817257572..9676cc736 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -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", }, }) @@ -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/); }); });