在我的组件中,AI 有一个功能可以根据组件 B 发出的数据更新视图。我不想集成组件 B 并制作一个实际的组件,即使这对于这个测试来说太复杂了。
我只想调用函数并将数据传递给函数。问题是,将数据作为“事件”发送到组件 A 中的函数似乎不起作用:
it('should update the video with the data from the edit component', () => {
let event;
event.title = 'New Title';
event.description = 'New Description';
event.link = 'New Link';
event.videoCategory = 'New Category';
event.categories = '2';
event.a14Only = 0;
component.updateVideoCard(event);
fixture.detectChanges();
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).toBe('0');
expect(component.editDisabled).toBeTruthy();
});
并且该事件以“未定义”结束。我还尝试将其设置为一个名为“事件”的 javascript 对象,其中包含键值对,但这也没有产生任何运气。
component.updateEvent(data) 代码:
updateVideoCard(event) {
this.videoTitle = event.title;
this.videoDescription = event.description;
this.videoLink = event.link;
this.videoCategory = event.category;
this.categoryID = event.categories;
if (event.a14Only === 1) {
this.a14Only = true;
} else {
this.a14Only = false;
}
this.enableEditor = false;
this.notification.done(`${this.videoTitle} updated successfully.`);
}