Hello,
Here is my code:
import { Test } from '@nestjs/testing';
import { TrendsService } from './platform-service';
import { createMock } from '@golevelup/ts-jest';
describe('PlatformController', () => {
beforeEach(async () => {
const module = await Test.createTestingModule({
imports: [],
controllers: [],
providers: [
{ provide: TrendsService, useValue: createMock<TrendsService>() },
],
}).compile();
});
describe('getTrendsAvailablePeriods', () => {
it('should call computeAvailableTrendPeriods with the correct account slug', async () => {
expect(true).toBe(true);
});
});
});
// Trends.service.ts
@Injectable()
export class TrendsService {
constructor(
private readonly bigQueryService: BigQueryService,
@Inject(CACHE_MANAGER) protected readonly cacheManager: Cache
) {}
...
As you can see, my test is trying to mock TrendsService. But just this small code is causing an error, because TrendsService constructor is calling BigQueryService which require custom env variable that I don't provide in my test environment. But it's not the issue, because I obviously don't want to do any BigQuery request in my tests.
My question is: shouldn't TrendsService be mocked here? Why is it being instantiated?
const module = await Test.createTestingModule({
imports: [],
controllers: [],
providers: [
{
provide: TrendsService,
useValue: {
test: 'zzz',
},
},
],
}).compile();
});
This code doesn't work either
Thanks a lot for your help!