我的spec.ts文件:
describe('CenterPricesComponent', () => {
let component: CenterPricesComponent;
let fixture: ComponentFixture<CenterPricesComponent>;
let service: MockPriceRulesService;
let centersService: MockCentersService;
beforeEach(async(() => {
service = new MockPriceRulesService(null);
centersService = new MockCentersService(null);
TestBed.overrideProvider(PriceRulesService, { useValue: service });
TestBed.overrideProvider(CentersService, { useValue: centersService});
TestBed.configureTestingModule(testBed).compileComponents();
fixture = TestBed.createComponent(CenterPricesComponent);
fixture.detectChanges();
component = fixture.componentInstance;
}));
.
.
.
在这里,我要用以前创建的伪造服务来模拟组件中使用的两个服务。我想知道是否可以使用这个componentInstance component
的HTML模板来做到这一点。
编辑:
constructor(
private priceruleService: PriceRulesService,
private windowService: NbWindowService,
private centerService: CentersService,
private route: ActivatedRoute
) { }
答案 0 :(得分:0)
如果您不想使用HTML,那么根本就不要使用测试床,它基本上就是为了使用它。
let component: CenterPricesComponent = new CenterPricesComponent(
// Your mocked dependencies
);
如果我不太清楚,则需要删除它。
let component: CenterPricesComponent = new CenterPricesComponent(
// Your activated route
{ snapshot: { paramMap : { get: () => '', } } } as any
);