akveo / ngx-admin-bundle-support

Support repository for ngx-admin backend bundles with issues tracking, instructions and code samples
58 stars 32 forks source link

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

Open wleecarter opened 4 years ago

wleecarter commented 4 years ago

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>(AppController);
  });
...
denStrigo commented 4 years ago

@wleecarter Thank you. Great job :fire:. We appreciate your time and your help :star2: