Я посмотрел на DebugElement.triggerEvent, но, к сожалению, документация устарела и мне не повезло, я сам понял, как это сделать.Похоже, что в любом случае также требовалось интегрировать второй компонент.
В итоге я интегрировал 2 компонента и просто запустил его с помощью стандартного объекта JSON из второго компонента, например:
describe('VideoCardComponent', () => {
let component: VideoCardComponent;
let fixture: ComponentFixture<VideoCardComponent>;
let fixture2: ComponentFixture<EditVideoComponent>;
let component2: EditVideoComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MatCardModule,
MatButtonModule,
BrowserAnimationsModule,
FontAwesomeModule,
BrowserModule,
FlexLayoutModule,
RouterTestingModule,
ReactiveFormsModule,
FormsModule,
MatSelectModule,
MatOptionModule,
MatInputModule,
MatSlideToggleModule
],
declarations: [VideoCardComponent, SafepipePipe, EditVideoComponent],
providers: [
{ provide: RestService, useClass: RestStub },
{ provide: NotificationService, useClass: NotificationStub }
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents()
.then(() => {
fixture2 = TestBed.createComponent(EditVideoComponent);
fixture = TestBed.createComponent(VideoCardComponent);
component = fixture.componentInstance;
component2 = fixture2.componentInstance;
fixture2.detectChanges();
fixture.detectChanges();
});
}));
Вывидно, что я просто назвал его component2 и fixture2 и добавил зависимости для обоих в одном и том же тестовом стенде 1.
Я, вероятно, назову их чем-то более актуальным, вместо component и component2.
фиксированный тест:
it('should update the video with the data from the edit component', () => {
const data = [
{
title: 'New Title',
description: 'New Description',
link: 'New Link',
category: 'New Category',
categories: '2',
a14Only: 0
}
];
component2.updateVideoCard.subscribe(newVideo => {
component.updateVideoCard(newVideo);
expect(component.videoTitle).toBe('New Title');
expect(component.videoLink).toBe('New Link');
expect(component.videoDescription).toBe('New Description');
expect(component.videoCategory).toBe('New Category');
expect(component.categoryID).toBe('2');
expect(component.a14Only).toBeFalsy();
expect(component.editDisabled).toBeFalsy();
});
component2.updateLocalVideoData(data);
fixture2.detectChanges();
fixture.detectChanges();
});