加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

TypeError {Angular测试中的ngDebugContext

发布时间:2020-12-17 07:11:04 所属栏目:安全 来源:网络整理
导读:这个单元测试 it('should invoke copy method',fakeAsync(() = { spyOn(testClipboardService,'copy'); linkEl = fixture.debugElement.query(By.css('.mat-raised-button')).nativeElement; linkEl.click(); expect(testClipboardService.copy).toHaveBeenC
这个单元测试

it('should invoke copy method',fakeAsync(() => {
    spyOn(testClipboardService,'copy');
    linkEl = fixture.debugElement.query(By.css('.mat-raised-button')).nativeElement;
    linkEl.click();
    expect(testClipboardService.copy).toHaveBeenCalled();
  }));

它成功通过但在控制台中我有一个错误,这引起了这一行:

linkEl.click();

我不明白为什么

‘ERROR’,TypeError{ngDebugContext: DebugContext_{view: Object{def: …,parent: …,viewContainerParent: …,parentNodeDef: …,context: …,component: …,nodes: …,state: …,root: …,renderer: …,oldValues: …,disposables: …,initIndex: …},nodeIndex: 0,nodeDef: Object{nodeIndex: …,renderParent: …,bindingIndex: …,outputIndex: …,checkIndex: …,flags: …,childFlags: …,directChildFlags: … etc

提前致谢

解决方法

在我的情况下,我能够通过在配置测试平台时将NoopAnimationsModule添加到我的导入来消除错误.基于我发现的内容,您可能在运行测试时缺少导入.

例:

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyAwesomeComponent ],imports: [
        NoopAnimationsModule,// I had to add this
        FormsModule,RouterTestingModule
      ]
    })
    .compileComponents();
  }));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读