Skip to content

Commit

Permalink
refactor: fix couple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
L2jLiga committed Oct 20, 2023
1 parent dc9a084 commit 1f4b102
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/decorators/error-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { FastifyReply, FastifyRequest } from 'fastify';
import { IErrorHandler as IErrorHandler } from '../interfaces/index.js';
import { ERROR_HANDLERS } from '../symbols/index.js';
import { ErrorHandler } from './error-handler.js';
import { getErrorHandlerContainer } from './helpers/class-metadata.js';
import ErrnoException = NodeJS.ErrnoException;

describe('Decorators: @IErrorHandler', function () {
it('should add annotated method to controller options', () => {
class WithHandlers {
static [ERROR_HANDLERS]: IErrorHandler[];

@ErrorHandler(TypeError)
public handleTypeError(error: TypeError) {
throw new Error(error.message);
Expand All @@ -25,7 +23,7 @@ describe('Decorators: @IErrorHandler', function () {
}
}

expect(WithHandlers[ERROR_HANDLERS].length).toBe(3);
expect(getErrorHandlerContainer(WithHandlers)).toBe(3);

const [typeErrorHandler, headersErrorHandler, genericHandler] = WithHandlers[ERROR_HANDLERS];
expect(typeErrorHandler.accepts(undefined)).toBe(false);
Expand Down
7 changes: 2 additions & 5 deletions lib/decorators/hook.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { FastifyReply, FastifyRequest } from 'fastify';
import { IHook } from '../interfaces/index.js';
import { HOOKS } from '../symbols/index.js';
import { Container } from './helpers/container.js';
import { getHooksContainer } from './helpers/class-metadata.js';
import { Hook } from './hook.js';

describe('Decorators: @IHook', () => {
Expand All @@ -13,8 +11,7 @@ describe('Decorators: @IHook', () => {
}
}

// @ts-expect-error HOOKS created implicitly
const hooks = Controller[HOOKS] as Container<IHook>;
const hooks = getHooksContainer(Controller);

expect(hooks).toHaveLength(1);
expect([...hooks][0]).toEqual({
Expand Down

0 comments on commit 1f4b102

Please sign in to comment.