nestjs-typed-events
Version:
Typesafe NestJS event emitter module
50 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const contract_1 = require("./contract");
const zod_1 = require("zod");
describe(contract_1.EventContractBuilder.name, () => {
describe('given multiple events', () => {
describe('when they have the same name', () => {
it('should overrite the first', () => {
const contract = contract_1.EventContractBuilder.create()
.required('test.event', zod_1.z.object({}))
.optional('test.event', zod_1.z.object({}))
.build();
expect(contract['test.event'].optional).toBeTruthy();
});
});
describe('when they have different names', () => {
it('should create contract containing all events', () => {
const contract = contract_1.EventContractBuilder.create()
.required('test.event', zod_1.z.object({}))
.required('test.event.other', zod_1.z.object({}))
.build();
expect(contract['test.event']).toEqual({
optional: false,
schema: expect.any(zod_1.ZodType),
});
expect(contract['test.event.other']).toEqual({
optional: false,
schema: expect.any(zod_1.ZodType),
});
});
});
});
describe('given required event', () => {
it('should mark event as required', () => {
const contract = contract_1.EventContractBuilder.create()
.required('test.event', zod_1.z.object({}))
.build();
expect(contract['test.event'].optional).toBeFalsy();
});
});
describe('given optional event', () => {
it('should mark event as optional', () => {
const contract = contract_1.EventContractBuilder.create()
.optional('test.event', zod_1.z.object({}))
.build();
expect(contract['test.event'].optional).toBeTruthy();
});
});
});
//# sourceMappingURL=contract.spec.js.map