Skip to content

Commit

Permalink
test: reduce indentation of test
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Oct 27, 2024
1 parent a0e4bec commit 7c5ffc4
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions test/context.type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,44 @@ import {
it,
} from "./deps.test.ts";

describe(
"ctx.has* checks",
() => {
it("should narrow down types", () => {
const c = new Composer<Context & { state: 1 }>();
c.use((ctx) => {
describe("ctx.has* checks", () => {
it("should narrow down types", () => {
const c = new Composer<Context & { state: 1 }>();
c.use((ctx) => {
assertType<IsExact<typeof ctx.state, 1>>(true);
if (ctx.has(":contact")) {
assertType<
IsExact<typeof ctx.msg.contact.phone_number, string>
>(true);
assertType<IsExact<typeof ctx.state, 1>>(true);
if (ctx.has(":contact")) {
assertType<
IsExact<typeof ctx.msg.contact.phone_number, string>
>(true);
assertType<IsExact<typeof ctx.state, 1>>(true);
}
if (ctx.hasText("123")) {
assertType<
Has<typeof ctx.match, string | RegExpMatchArray>
>(true);
}
if (ctx.hasCommand("123")) {
assertType<Has<typeof ctx.match, string>>(true);
}
if (ctx.hasChatType("private")) {
assertType<IsExact<typeof ctx.chat.type, "private">>(true);
}
if (ctx.hasGameQuery("123")) {
assertType<
IsExact<
typeof ctx.callbackQuery.game_short_name,
string
>
>(true);
}
if (ctx.hasInlineQuery("123")) {
assertType<IsExact<typeof ctx.inlineQuery.id, string>>(
true,
);
}
});
c.command("c", (ctx) => {
}
if (ctx.hasText("123")) {
assertType<
Has<typeof ctx.match, string | RegExpMatchArray>
>(true);
}
if (ctx.hasCommand("123")) {
assertType<Has<typeof ctx.match, string>>(true);
});
}
if (ctx.hasChatType("private")) {
assertType<IsExact<typeof ctx.chat.type, "private">>(true);
}
if (ctx.hasGameQuery("123")) {
assertType<
IsExact<
typeof ctx.callbackQuery.game_short_name,
string
>
>(true);
}
if (ctx.hasInlineQuery("123")) {
assertType<IsExact<typeof ctx.inlineQuery.id, string>>(
true,
);
}
});
},
);
c.command("c", (ctx) => {
assertType<Has<typeof ctx.match, string>>(true);
});
});
});

0 comments on commit 7c5ffc4

Please sign in to comment.