Я пишу контрольный пример для углового компонента, который сильно зависит от службы с именем UserRecordFormService
, которая содержит список методов, для тех, которые отправляют запрос http
. Я создал фиктивный класс (для переопределения). методы), и хотел, чтобы TestBed
расширил все другие функции от самого UserRecordFormService
.
Я взял ссылку из нескольких источников и мог пройти создание компонента, но он выдает ошибки из всех других тестовых спецификаций, а также не проходит тестовые спецификации из других компонентов. Я что-то здесь упустил, пожалуйста, помогите мне определить мою ошибку.
describe('UserRecordFormComponent', () => {
let component: UserRecordFormComponent;
let fixture: ComponentFixture<UserRecordFormComponent>;
class UserRecordFormServiceStub {
//some methods returning data;
}
class AppLookupServiceStub {
//some methods returning data;
}
class AppRouterStub {
navigate() {}
}
const tb_base = {
imports: [
RouterTestingModule,
BrowserAnimationsModule,
RouterModule,
BrowserDynamicTestingModule
],
providers: [
UserRecordFormService,
AppHttpService,
HttpClient,
AppCookieService,
CookieService,
HttpHandler,
{ provide: AppLookupService, useClass: AppLookupServiceStub },
{ provide: ActivatedRoute, useValue: {
outlet: "primary",
data: {
actionId: "E",
buttonDesc: "Update"
},
params: of({
id: "0009"
}),
queryParams: of({
objectKey: "36353639373739393535353E352525252525253E3E3E3E363738363735363D3637363B353535"
}),
snapshot: {
data: {
actionId: "E",
buttonDesc: "Update"
},
queryParams: {
objectKey: "36353639373739393535353E352525252525253E3E3E3E363738363735363D3637363B353535"
}
}
}},
{ provide: Router, useClass: AppRouterStub }
],
declarations: [UserRecordFormComponent],
schemas: [NO_ERRORS_SCHEMA]
};
let UserRecordFormServiceStub = UserRecordFormServiceStub;
beforeEach(async(() => {
TestBed.configureTestingModule(tb_base)
.compileComponents();
}))
beforeEach(() => {
fixture = TestBed.createComponent(UserRecordFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
it('should create component', inject([UserRecordFormService], (loader: UserRecordFormServiceStub) => {
expect(component).toBeTruthy();
}));
it('should show expected output for ',inject([UserRecordFormService], (loader: UserRecordFormServiceStub) => {
expect(component.actionButtonDesc).toEqual("Update");
expect(component.subtypeName).toEqual("0 - Main bank");
}));
})
Я взял ссылки отсюда: https://github.com/angular/quickstart/issues/320
https://github.com/angular/angular/issues/10943
Ошибка : «Uncaught TypeError: Невозможно прочитать свойство 'message' с неопределенным брошенным", это ошибка, которую оно выдает из спецификации тестирования других компонентов, т.е. UserListComponent
. Вызывает ли инжектор какие-либо проблемы с другими компонентами.
Пожалуйста, дайте мне знать, если я что-то здесь упускаю.