我发现可能我的测试从未执行过。因为输出中测试描述的颜色既不是绿色也不是红色。
可能是我错了。
我还发现,如果我注释掉component.ngOnInit();
,它会很好地工作
我提供了我所有的spec文件代码,而没有遗漏任何可能成为问题的东西。
SPEC
class AppConstantsStub {
public userPreferences = {
modelData: {
basicDetails: {
itemId: 3 // some other valid value here is fine
}
},
UserBasicDetails: {
// some valid values here, maybe
}
};
}
class ComponentDetailsServiceStub {
defaultProperties = {
editable: false,
showToolbar: false,
viewMode: false,
editMode: false,
showPopup: true,
formSavedClicked: false,
cancelClicked: false,
refresh: false,
};
push(value){
this.propertiesSource.next(value);
}
private propertiesSource = new BehaviorSubject(this.defaultProperties);
currentProperties = this.propertiesSource.asObservable();
setDefaultCancelClicked() { }
}
class SearchAPIServiceStub {
}
class UOMServiceStub { }
class BomDetailsServiceStub { }
class FormBuilderUtilsServiceStub { }
class DMServiceStub { }
class GlobalLoaderServiceStub {
hideLoader() { }
}
class SCNotificationServiceStub { }
class CreateRfxServiceStub { }
class LayoutServiceStub { }
class GridFilterServiceStub {
searchConfig() { return null; }
}
describe('component details', () => {
let componentDetailsComponent: ComponentDetailsComponent;
let subject: ComponentDetailsComponent;
let formBuilderUtilsService: FormBuilderUtilsService;
let appConstants: AppConstants;
let componentDetailsService: ComponentDetailsServiceStub;
let dMService: DMService;
let globalLoaderService: GlobalLoaderServiceStub;
let sCNotificationService: SCNotificationService;
let createRfxService: CreateRfxService;
let layoutService: LayoutService;
let gridFilterService: GridFilterService;
let mode: string;
let fixture: ComponentFixture<ComponentDetailsComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ComponentDetailsComponent],
providers: [
{ provide: FormBuilderUtilsService, useClass: FormBuilderUtilsServiceStub },
{ provide: AppConstants, useClass: AppConstantsStub },
{ provide: ComponentDetailsService, useClass: ComponentDetailsServiceStub },
{ provide: DMService, useClass: DMServiceStub },
{ provide: GlobalLoaderService, useClass: GlobalLoaderServiceStub },
{ provide: SCNotificationService, useClass: SCNotificationServiceStub },
{ provide: CreateRfxService, useClass: CreateRfxServiceStub },
{ provide: LayoutService, useClass: LayoutServiceStub },
{ provide: GridFilterService, useClass: GridFilterServiceStub },
],
schemas: [NO_ERRORS_SCHEMA]
});
// subject = TestBed.get(ComponentDetailsComponent);
fixture = TestBed.createComponent(ComponentDetailsComponent);
subject = fixture.componentInstance;
componentDetailsService = TestBed.get(ComponentDetailsService);
fixture.detectChanges();
});
it('should create componentDetailsComponent', () => {
expect(1).toBe(2);
});
}
);