We have a method decorator that is applied to the routes in one of the controllers. This decorator takes a boolean value set at the configuration files and that changes for each environment.
We would like to test this decorator in the e2e tests by altering the configuration value dynamically, which we already managed to do it. We use the config npm package not the @nestjs/config one.
However, the controller file is loaded before the changes are applied, even though the import of the controller is after doing these changes.
The question is how we could reload or recompile the controller to take into account the modified value so that the decorator will change its behavior.
This is how we create the module from which we spin off the NestJs app for this test
const moduleRef = await Test.createTestingModule({
imports: [AuthModule],
controllers: [AuthNestController],
})
.overrideProvider(IAuthProvider)
.useClass(TestAuthProvider)
.compile();
A solution to force loading the controller code after doing the changes will also be welcome.
Aucun commentaire:
Enregistrer un commentaire