cqrs-eda
Version:
Lightweight CQRS and Event-Driven Architecture library using TypeScript decorators, handlers and typings. Perfect for scalable event-driven apps.
41 lines (32 loc) • 1.16 kB
text/typescript
import { describe, it, expect, beforeEach } from "vitest";
import { Query, getQueryRegistry } from "./decorators";
describe("Query decorator and registry", () => {
beforeEach(() => {
getQueryRegistry().clear();
});
it("should register a query class with the given name", () => {
class TestQuery {}
const registry = getQueryRegistry();
expect(registry.has("TEST_QUERY")).toBe(true);
expect(registry.get("TEST_QUERY")).toBe(TestQuery);
});
it("should throw an error if registering a query with a duplicate name", () => {
class QueryOne {}
expect(() => {
class QueryTwo {}
}).toThrowError('Query with name "DUPLICATE_QUERY" is already registered.');
});
it("should register multiple different queries without conflict", () => {
class QueryOne {}
class QueryTwo {}
const registry = getQueryRegistry();
expect(registry.size).toBe(2);
expect(registry.get("QUERY_ONE")).toBe(QueryOne);
expect(registry.get("QUERY_TWO")).toBe(QueryTwo);
});
});