Skip to content

Commit

Permalink
fix: add test where types is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
l0kal committed Mar 7, 2022
1 parent 3e6b388 commit 114d4e0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/decorators/typed-headers.decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
async test(@TypedHeaders() headers: TestHeaders): Promise<string> {
return headers.countryCode;
}
}
Expand Down Expand Up @@ -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<string> {
return headers.countryCode;
}
}
}).toThrow(
new Error(
'Type metadata not found. See https://www.typescriptlang.org/docs/handbook/decorators.html#metadata'
)
);
});
});

0 comments on commit 114d4e0

Please sign in to comment.