Skip to content

Schema validation in tests #800

Answered by L2jLiga
AmusedArg asked this question in Q&A
Aug 9, 2022 · 1 comments · 9 replies
Discussion options

You must be logged in to vote

Hi there!

I think you can workaround this issue in tests by using plugins option. Something like this I guess

describe('Controller: CalculatorController', () => {
  let instance: FastifyInstanceWithController<CalculatorController>;
  const myService = {someFunction: jest.fn()};
  beforeAll(async () => {
    instance = await configureControllerTest({
      controller: CalculatorController,
      mocks: [
        {
          provide: MyService,
          useValue: myService,
        },
      ],
      plugins: [
        (instance) => instance.addSchema(authorizationHeaderSchema)
      ]
    });
  });
});

If this schema comming from another plugin then you can replace this "self written plugi…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@L2jLiga
Comment options

@AmusedArg
Comment options

@L2jLiga
Comment options

@L2jLiga
Comment options

@AmusedArg
Comment options

Answer selected by L2jLiga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants