Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 10, 2023
1 parent f5984a2 commit 5224f03
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
createError,
} from "../src";

const readableStreamSupported =
typeof ReadableStream !== "undefined"; /* Node.js 16 */

describe("app", () => {
let app: App;
let request: SuperTest<Test>;
Expand Down Expand Up @@ -102,7 +105,7 @@ describe("app", () => {
expect(JSON.parse(res.text).statusMessage).toBe("test");
});

it.skipIf(typeof ReadableStream === undefined)("Web Stream", async () => {
it.runIf(readableStreamSupported)("Web Stream", async () => {
app.use(
eventHandler(() => {
return new ReadableStream({
Expand All @@ -120,27 +123,24 @@ describe("app", () => {
expect(res.header["transfer-encoding"]).toBe("chunked");
});

it.skipIf(typeof ReadableStream === undefined)(
"Web Stream with Error",
async () => {
app.use(
eventHandler(() => {
return new ReadableStream({
start() {
throw createError({
statusCode: 500,
statusText: "test",
});
},
});
})
);
const res = await request.get("/");
it.runIf(readableStreamSupported)("Web Stream with Error", async () => {
app.use(
eventHandler(() => {
return new ReadableStream({
start() {
throw createError({
statusCode: 500,
statusText: "test",
});
},
});
})
);
const res = await request.get("/");

expect(res.statusCode).toBe(500);
expect(JSON.parse(res.text).statusMessage).toBe("test");
}
);
expect(res.statusCode).toBe(500);
expect(JSON.parse(res.text).statusMessage).toBe("test");
});

it("can return HTML directly", async () => {
app.use(eventHandler(() => "<h1>Hello world!</h1>"));
Expand Down

0 comments on commit 5224f03

Please sign in to comment.