From 114d4e09cca1461ff4e227aef9b3db2449b088a0 Mon Sep 17 00:00:00 2001 From: Thomas Hedemann Hansen Date: Mon, 7 Mar 2022 13:22:17 +0100 Subject: [PATCH] fix: add test where `types` is undefined --- .../typed-headers.decorator.spec.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/decorators/typed-headers.decorator.spec.ts b/src/decorators/typed-headers.decorator.spec.ts index fe308e9..e770614 100644 --- a/src/decorators/typed-headers.decorator.spec.ts +++ b/src/decorators/typed-headers.decorator.spec.ts @@ -27,10 +27,7 @@ export class TestHeaders { @Controller({ path: 'test', version: '1' }) export class TestController { @Get() - async test( - // @Headers() @HeaderSchema(TransactionHeaders) headers: TransactionHeaders, - @TypedHeaders() headers: TestHeaders - ): Promise { + async test(@TypedHeaders() headers: TestHeaders): Promise { return headers.countryCode; } } @@ -75,4 +72,23 @@ describe('TypedHeaders decorator', () => { error: 'Bad Request', }); }); + + it('fails when emitDecoratorMetadata is disabled', async () => { + expect(() => { + jest.spyOn(Reflect, 'getOwnMetadata').mockReturnValue(undefined); + + @Controller({ path: 'test', version: '1' }) + // eslint-disable-next-line @typescript-eslint/no-unused-vars + class TestControllerWithoutEmitDecoratorMetadata { + @Get() + async test(@TypedHeaders() headers: TestHeaders): Promise { + return headers.countryCode; + } + } + }).toThrow( + new Error( + 'Type metadata not found. See https://www.typescriptlang.org/docs/handbook/decorators.html#metadata' + ) + ); + }); });