Jasmine:无法读取未定义的 属性 'api'
Jasmine: Cannot read property 'api' of undefined
我有一个使用 ag-grid 来显示数据的应用程序。此数据只是用户信息,例如他们的姓名和电子邮件。我正在为组件 class 中的一个函数编写测试。我的函数是这样的:它使用 getData 服务从 url 中检索用户列表。然后将这些用户输出到 ag-grid。我的测试正试图准确地模拟这一点。这是我的组件 class:
的函数
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);
}))
我的测试应该通过并且 rowData 应该等于响应。
线上:dashboardComponent.getUsers() 我收到错误:无法读取未定义的 属性 'Api'谢谢。
所以如果有人遇到这个问题,我解决了。正如我所说,Jasmine 在使用 AGGrid 时遇到了麻烦。为了解决这个问题,在我的测试中,我添加了一行: spyOn(component'redrawAgGrid');
通过网上的研究, api 错误通常是由于未调用 redrawAGrid 方法引起的。
我有一个使用 ag-grid 来显示数据的应用程序。此数据只是用户信息,例如他们的姓名和电子邮件。我正在为组件 class 中的一个函数编写测试。我的函数是这样的:它使用 getData 服务从 url 中检索用户列表。然后将这些用户输出到 ag-grid。我的测试正试图准确地模拟这一点。这是我的组件 class:
的函数 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);
}))
我的测试应该通过并且 rowData 应该等于响应。 线上:dashboardComponent.getUsers() 我收到错误:无法读取未定义的 属性 'Api'谢谢。
所以如果有人遇到这个问题,我解决了。正如我所说,Jasmine 在使用 AGGrid 时遇到了麻烦。为了解决这个问题,在我的测试中,我添加了一行: spyOn(component'redrawAgGrid');
通过网上的研究, api 错误通常是由于未调用 redrawAGrid 方法引起的。