茉莉AG网格测试案例失败

发布于 2025-01-26 05:50:16 字数 745 浏览 4 评论 0原文

我正在尝试编写用于Ag网格导出方法的测试。 这是组件更改

export class GridComponent extendsimplements OnInit {

  gridApi: any;

  onGridDataExport(): void {
    this.gridApi.exportDataAsCsv();
  }
}

网格组件规格文件

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv');
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });

  });

当我运行测试用例时,它显示以下错误

我该如何解决此问题?

期望有效的解决方案。

提前致谢

Am trying to write a test for ag grid export method.
Here is the component changes

export class GridComponent extendsimplements OnInit {

  gridApi: any;

  onGridDataExport(): void {
    this.gridApi.exportDataAsCsv();
  }
}

grid component spec file

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv');
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });

  });

when i run the test cases it show the below error
enter image description here

How can i resolve this issue?

expecting a valid solution.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2025-02-02 05:50:16

尝试以下尝试:

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv').and.callThrough();
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });
});

如果您查看我的代码,我正在添加.and.callthrough();,并且您需要使用它,因为使用此代码,您真的在等待执行方法<代码> exportDataAscsv 。

Try with this:

fdescribe('when onGridDataExport method call', () => {
    it('should call gridApi', () => {
      const result = spyOn(component.gridApi, 'exportDataAsCsv').and.callThrough();
      component.onGridDataExport();
      expect(result).toHaveBeenCalled();
    });
});

If you look my code, I'm adding .and.callThrough(); and you need to use this because with this code you're really waiting for the execution of the method exportDataAsCsv.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文