I am trying to make the documentation example work with a module that imports MongooseModule.
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { CatsModule } from '../../src/cats/cats.module';
import { CatsService } from '../../src/cats/cats.service';
import { INestApplication } from '@nestjs/common';
describe('Cats', () => {
let app: INestApplication;
let catsService = { findAll: () => ['test'] };
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [CatsModule],
})
.overrideProvider(CatsService)
.useValue(catsService)
.compile();
app = moduleRef.createNestApplication();
await app.init();
});
it(`/GET cats`, () => {
return request(app.getHttpServer())
.get('/cats')
.expect(200)
.expect({
data: catsService.findAll(),
});
});
afterAll(async () => {
await app.close();
});
});
This is my CatsModule
@Module({
imports: [MongooseModule.forFeature([{name: Cats.name, schema: CatsSchema,}])],
controllers: [CatsController],
providers: [CatsService],
})
export class CatsModule {}
This is the error that I get
Nest can't resolve dependencies of the CatsModel (?). Please make sure that the argument DatabaseConnection at index [0] is available in the MongooseModule context.
So a couple of questions here
- why is Nest requiring the
CatsModelifCatsControllerdoesn't use it and theCatsServiceis mocked? - if it's just because of the
importsarray, how do I mock it so it stops requiring theDatabaseConnectiontoo? I am certain I don't want to use either in my tests.