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

Unable to change input value for afterNextRender from unit test

Discussão em 'Angular' iniciado por Murhaf Sousli, Setembro 11, 2024.

  1. I am trying to write unit test for my component but I am unable to change my input value inside afterNextRender

    // In component code
    constructor() {
    afterNextRender({
    write: () => {
    if (this.disabled()) {
    this.myStream.next('hello');
    }
    }
    });
    }

    // in unit test
    it('should call the function when disabled is true', async () => {

    fixture.componentRef.setInput('disabled', true);

    await firstValueFrom(component.myStream);

    expect(component.disabled()).toEqual(true);
    });


    The test wait forever then fails. the problem that disabled input is false when afterNextRender executes, I need to be able to set the input first then run it, similar to how we do with ngOnInit for instance. how can I do this test with afterNextRender?

    Continue reading...

Compartilhe esta Página