Skip to content

Overriding guard doesn't work when testing #10366

@juliengbt

Description

@juliengbt

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hello,

Overriding a guard with the method below doesn't actually override the guard.

testingModule
      .overrideGuard(MyGuard)
      .useValue({ canActivate: () => true })
      .compile();

Minimum reproduction code

https://github.com/juliengbt/nestjs-guard-override

Steps to reproduce

  1. npm install
  2. npm run test:e2e

Expected behavior

test should not fail because the guard should be overridden

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9.0.0

Packages versions

"dependencies": {
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/passport": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/platform-fastify": "^9.1.3",
    "passport": "^0.6.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  }

Node.js version

16.14.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions