茉莉花:无法读取未定义的属性'api'



>我有一个使用ag-grid来显示数据的应用程序。此数据只是用户信息,例如他们的姓名和电子邮件。我正在为组件类中的一个函数编写测试。我的函数的作用是这样的:它使用 getData 服务从 url 中检索用户列表。然后将这些用户输出到农业电网。 我的测试试图完全模拟这一点。这是我的组件类中的函数:

getUsers() {
this.userService.getData(url_UserList).subscribe(res=>  
this.rowData = res;
this.redrawAgGrid();
}

现在这是我的测试:

fit('should call getData and return list of users', async(() => {
const response: Test[] = [];
spyOn(httpService, 'getData').and.returnValue(of(response));
dashboardComponent.getUsers();
fixture.detectChanges();
expect(dashboardComponent.rowData).toEqual(response);
}))

我的测试应该通过,行数据应该等于响应。在线上: dashboardComponent.getUsers((我收到错误:无法读取未定义的属性"Api">谢谢。

所以如果有人碰巧遇到这个问题,我解决了。茉莉花在AGGrid上遇到了麻烦,就像我说的那样。为了解决这个问题,在我的测试中,我添加了以下行:spyOn(component'redrawAgGrid');通过在线研究,api错误通常是由于方法redrawAGrid未被调用。

最新更新