Our great sponsors
-
jest-mock-extended
Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
testing-nestjs
A repository to show off to the community methods of testing NestJS including Unit Tests, Integration Tests, E2E Tests, pipes, filters, interceptors, GraphQL, Mongo, TypeORM, and more!
Example https://github.com/leosuncin/nest-api-example/blob/master/src/auth/interceptors/token.interceptor.spec.ts
You can use something like jest-mock-extended or @golevelup/ts-jest to mock it, and whether your interceptor has dependencies or not, can be more complex or simpler how you instance it.
Example https://github.com/jmcdo29/testing-nestjs/blob/8519ae7043d1dde5ae12a5d8f8ab02ea3c3c2fcf/apps/complex-sample/src/cat/cat.interceptor.spec.ts
It depends of how you mock the request and response that you passed to ExecutionContext because the response should be modified. I recommend you to use node-mocks-http