Skip to content

Commit

Permalink
Define signals in tests cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Aug 13, 2023
1 parent 4d8e68e commit d84993c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/api/test/unit/client/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ describe("FetchError", function () {
id: string;
url?: string;
requestListener?: http.RequestListener;
abort?: true;
timeout?: true;
signalHandler?: () => AbortSignal;
errorType: FetchErrorType;
errorCode: string;
expectCause: boolean;
Expand Down Expand Up @@ -66,20 +65,20 @@ describe("FetchError", function () {
},
{
id: "Aborted request",
abort: true,
requestListener: () => {
// leave the request open until aborted
},
signalHandler: () => AbortSignal.abort(),
errorType: "aborted",
errorCode: "ERR_ABORTED",
expectCause: false,
},
{
id: "Timeout request",
timeout: true,
requestListener: () => {
// leave the request open until timeout
},
signalHandler: () => AbortSignal.timeout(10),
errorType: "timeout",
errorCode: "ERR_TIMEOUT",
expectCause: false,
Expand All @@ -100,7 +99,7 @@ describe("FetchError", function () {
});

for (const testCase of testCases) {
const {id, url = `http://localhost:${port}`, requestListener, abort, timeout} = testCase;
const {id, url = `http://localhost:${port}`, requestListener, signalHandler} = testCase;

it(id, async function () {
if (requestListener) {
Expand All @@ -117,8 +116,7 @@ describe("FetchError", function () {
);
}

const signal = abort ? AbortSignal.abort() : timeout ? AbortSignal.timeout(1) : null;
await expect(fetch(url, {signal})).to.be.rejected.then((error: FetchError) => {
await expect(fetch(url, {signal: signalHandler?.()})).to.be.rejected.then((error: FetchError) => {
expect(error.type).to.be.equal(testCase.errorType);
expect(error.code).to.be.equal(testCase.errorCode);
if (testCase.expectCause) {
Expand Down

0 comments on commit d84993c

Please sign in to comment.