1

Update: answer is here https://stackoverflow.com/a/35319780/7729975

Angular 8.

In my child component, I have:

   @Output() selectedProduct = new EventEmitter<Product>();

   handleProductSelection(product: Product){

    this.selectedProduct.emit(product);

    }

child.component.html:

<button *ngFor="let product of products" (click)="handleProductSelection(product)">{{product.productName}}</button>

I want to write a unit test that confirms that when called, handleProductSelection() will force selectedProduct to emit the product passed.

So far I have:

 it("selected product is emitted out", () => {
    const product = new Product(SampleProducts[0])
    component.handleProductSelection(product);
    component.selectedProduct.subscribe() // dont catch it

  });

Basicaly, after the method is invoked, I want to capture the emitted value to make sure the passed/clicked product is what is emitted to the parent.

Wede Asmera Tseada
  • 513
  • 2
  • 4
  • 14

0 Answers0