Test coverage not detected with toSignal and debounceTime

Discussão em 'Angular' iniciado por Oscar Saro, Agosto 7, 2025.

  1. Oscar Saro

    Oscar Saro Guest

    I have a component in my Angular project (v18.2.13) that has a reactive form to change a price field & an observable with the product info. I want to make a signal to know if the price form field has changed from the original product price. This is the code that I have and it's working.

    detailForm: FormGroup = this.#formBuilder.group({
    price: ['', [validatePrice()]]
    });

    product$ = of({ regularPvp: 12 }) //This is an example of what it could look like

    hasChangesFromRegularPrice = toSignal(
    this.detailForm.controls.price.valueChanges.pipe(
    debounceTime(300),
    combineLatestWith(this.product$),
    map(([value, product]) => {
    if (!value) {
    return true;
    }

    const parsedValue = parseLocaleFloat(value);

    return parsedValue !== product.regularPvp;
    })
    )
    );


    Since the input field in a text field, I've added a debounce to avoid checking every time a key is pressed.

    The problem is while testing, although the tests work, I can not check the coverage of this function, I haven't found the way to make it check that it went though. I can put logs inside the function and it logs the message, but the coverage is not detected.

    I have tried fakeAsync/tick but it does not seem to work. Without the debounceTime there is no problem, code works fine and coverage is detected. I have tried also consuming the signal in the test, but wouldn't go though the debounceTime.

    I'm testing with Karma & Jasmine.

    Is there any way to avoid removing the debounceTime?

    Continue reading...

Compartilhe esta Página