【发布时间】:2021-03-11 17:18:12
【问题描述】:
我尝试测试一个新类和构造函数,我有一个 configService.get。
@Injectable()
export class StripeService {
private stripe: Stripe;
constructor(private configService: ConfigService) {
const secretKey = configService.get<string>('STRIPE_SECRET') || '';
this.stripe = new Stripe(secretKey, {
apiVersion: '2020-08-27',
});
}
}
这是我的测试课:
import { Test, TestingModule } from '@nestjs/testing';
import { StripeService } from './stripe.service';
import { ConfigService } from '@nestjs/config';
const mockStripe = () => ({})
describe('StripeService', () => {
let service: StripeService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [StripeService,
{ provide: ConfigService, useFactory: mockStripe}
],
}).compile();
service = module.get<StripeService>(StripeService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
当我尝试运行我的测试时,我遇到了这个错误:
如果有人有解决方案的想法,我想解释一下。
【问题讨论】:
标签: typescript testing jestjs nestjs