akveo / akveo/ngx-admin-bundle-support

Failing unit test on NestJS Starter Kit app.controller.spec.ts

Aperta
#72 1 commento 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
56
Fork
30
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

`npm test` results in a failed test and this error message:

> Nest can't resolve dependencies of the AppController (AppService, ?). Please make sure that the argument at index [1] is available in the _RootTestModule context.

a mock provider for the `SeedService` should also be injected, since app controller also has a dependency on it. Here is the corrected code which generates a passing test:

```
describe('AppController', () => {
let appController: AppController;
const mockSeedService = {
checkAndSeed: () => {},
};

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [
AppService,
{
provide: 'SeedService',
useValue: mockSeedService,
},
],
}).compile();

appController = app.get(AppController);
});
...
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.