1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

TypeError: Cannot read property 'dispatchEvent' of null

Discussão em 'Angular' iniciado por Vijay Prajapati, Outubro 6, 2024.

  1. A written emit method test case in Angular now facing an issue is TypeError: Cannot read property 'dispatchEvent' of null.

    Get the click event end call to emit method. child component Html file

    article.html

    <a (click)="edit(item)" class="mat-card-title" style="cursor: pointer">{{ item.title }}</a>


    viewArticle.spec.ts

    fit('emiter call', () => {
    const fixture2 = TestBed.createComponent(ArticleCarouselComponent);
    const component2 = fixture2.componentInstance;
    spyOn(component2.changeevent, 'emit');
    const nativeElement = fixture.nativeElement;
    const button = nativeElement.querySelector('a');
    button.dispatchEvent(new Event('click'));
    fixture.detectChanges();
    expect(component2.changeevent.emit).toHaveBeenCalled();
    });


    TypeError: Cannot read property 'dispatchEvent' of null

    Continue reading...

Compartilhe esta Página