Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError{ngDebugContext in Angular tests

This unit test

 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();
  }));

it successfully passed but in console I have an error which provoked this line:

linkEl.click();

I don't understand why

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

Thanks in advance

like image 203
Artem Bogdan Avatar asked Mar 05 '18 11:03

Artem Bogdan


1 Answers

In my case, I was able to get rid of the error by adding the NoopAnimationsModule to my imports when configuring testbed. Based on what I found, you are probably missing an import when running your tests.

Example:

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyAwesomeComponent ],
      imports: [
        NoopAnimationsModule, // I had to add this
        FormsModule,
        RouterTestingModule
      ]
    })
    .compileComponents();
  }));
like image 127
Jacques ジャック Avatar answered Sep 23 '22 01:09

Jacques ジャック