I'm trying to replace my logger provider in a unit test file with a stubbed provider so that I don't get logs during unit tests from the tested module. I'm getting the following error:
error TS2322: Type '{ provide: string; useValue: {}; }' is not assignable to type 'Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference<any>'.
Object literal may only specify known properties, and 'provide' does not exist in type 'Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference<any>'.
21 provide: WINSTON_MODULE_PROVIDER,
My Code:
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
providers: [MyService],
imports: [
{
provide: WINSTON_MODULE_PROVIDER, // Error on this line
useValue: {},
},
],
}).compile();
MyService = moduleRef.get<MyService>(MyService);
});
And here's the constructor of the module i'm testing
constructor(
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
) {}
CodePudding user response:
Custom providers go in the providers
array, not the imports
. Providers never go in the imports
array.