mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
public commit
This commit is contained in:
38
app/__test__/Module.spec.ts
Normal file
38
app/__test__/Module.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { type TSchema, Type, stripMark } from "../src/core/utils";
|
||||
import { Module } from "../src/modules/Module";
|
||||
|
||||
function createModule<Schema extends TSchema>(schema: Schema) {
|
||||
class TestModule extends Module<typeof schema> {
|
||||
getSchema() {
|
||||
return schema;
|
||||
}
|
||||
toJSON() {
|
||||
return this.config;
|
||||
}
|
||||
useForceParse() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return TestModule;
|
||||
}
|
||||
|
||||
describe("Module", async () => {
|
||||
test("basic", async () => {});
|
||||
|
||||
test("listener", async () => {
|
||||
let result: any;
|
||||
|
||||
const module = createModule(Type.Object({ a: Type.String() }));
|
||||
const m = new module({ a: "test" });
|
||||
|
||||
await m.schema().set({ a: "test2" });
|
||||
m.setListener(async (c) => {
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
result = stripMark(c);
|
||||
});
|
||||
await m.schema().set({ a: "test3" });
|
||||
expect(result).toEqual({ a: "test3" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user