Skip to content

Commit

Permalink
fix: composer not being recognized as valid middleware for default ha…
Browse files Browse the repository at this point in the history
…ndler (#59)

* fix: composer not being recognized as middleware

* fix: utils tests filename

* add: test for Composer[]
  • Loading branch information
carafelix authored Dec 26, 2024
1 parent 5f1890d commit 8939b39
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/checks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Middleware } from "../deps.deno.ts";
import { Composer, Context, Middleware } from "../deps.deno.ts";
import { CommandOptions } from "../types.ts";
import { MaybeArray } from "./array.ts";

Expand All @@ -12,6 +12,7 @@ export function isMiddleware<C extends Context = Context>(
obj: unknown,
): obj is MaybeArray<Middleware<C>> {
if (!obj) return false;
if (obj instanceof Composer) return true;
if (Array.isArray(obj)) return obj.every(isMiddleware);
const objType = typeof obj;

Expand Down
27 changes: 27 additions & 0 deletions test/utils-test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { isMiddleware } from "../src/utils/checks.ts";
import { CommandsFlavor } from "../src/context.ts";
import { CommandGroup, commandNotFound } from "../src/mod.ts";
import { dummyCtx } from "./context.test.ts";
import {
assert,
assertEquals,
assertFalse,
Context,
describe,
it,
} from "./deps.test.ts";
import { Composer } from "../src/deps.deno.ts";

describe("Utils tests", () => {
describe("isMiddleware", () => {
it("Composer", () => {
const composer = new Composer();
assert(isMiddleware(composer));
});
it("Composer[]", () => {
const a = new Composer();
const b = new Composer();
assert(isMiddleware([a, b]));
});
});
});

0 comments on commit 8939b39

Please sign in to comment.