chore: add tests for fresh/compat imports (#3036)
- `fresh/compat - defineFn mixed return types` - Tests all supported return types (Response, VNode, null) with both sync and async handlers, including FreshContext parameter usage - `fresh/compat - multiple compat imports` - Tests importing multiple compat functions simultaneously close #3025 --patch-1 try to use deno/std Api to replace --patch-2 make it simple and clean --patch-3 Convert update_test.ts to .tsx for JSX support Use static imports instead of dynamic imports for better performance Switch from @std/assert to @std/expect for consistency Use ReturnType<> for automatic type inference instead of manual type definitions Sincerely grateful to @iuioiua for the guidance and patience. --------- Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com> Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
co-authored by
李嘉图·M·路
Asher Gomez
parent
c3c79352b0
commit
75897de196
@@ -0,0 +1,16 @@
|
||||
import type { FreshContext } from "./context.ts";
|
||||
import { assertType, type IsExact } from "@std/testing/types";
|
||||
import { expect } from "@std/expect";
|
||||
import { type defineApp, type defineLayout, defineRoute } from "./compat.ts";
|
||||
|
||||
Deno.test("compat - defineFn works", () => {
|
||||
const ctx = {} as FreshContext<unknown>;
|
||||
expect(defineRoute(() => new Response("test"))(ctx)).toBeInstanceOf(Response);
|
||||
expect(defineRoute(() => <span>test</span>)(ctx)).toBeInstanceOf(Object);
|
||||
expect(defineRoute(() => null)(ctx)).toEqual(null);
|
||||
});
|
||||
|
||||
Deno.test("compat - functions equivalent", () => {
|
||||
assertType<IsExact<typeof defineApp, typeof defineRoute>>(true);
|
||||
assertType<IsExact<typeof defineRoute, typeof defineLayout>>(true);
|
||||
});
|
||||
Reference in New Issue
Block a user