How to test Angular's output signal?

Discussão em 'Angular' iniciado por Irina S., Abril 29, 2025.

  1. Irina S.

    Irina S. Guest

    I have an output signal in my component like this:

    updatedBook = output<Book>();
    ...
    updateBook(changedBook: Book){
    this.updatedBook.emit(changedBook);
    }


    In the template I have a binding like this:

    <my-component
    (updatedBook)="onBookUpdate($event)"
    ></my-component>


    And in the parent component I use the emitted value like this:

    onBookUpdate(updatedBook: Book) {
    this.book = Book;
    }


    How can I write a unit test for it? I would like to verify that the updatedBook.emit() was called.

    Continue reading...

Compartilhe esta Página