Reputation: 127
@Input('price')
set setPrice(price) {
this.price = price;
this.modifyTotalAmount();
}
it('should call function ', () => {
spyOn(fixture.componentInstance, 'modifyTotalAmount');
fixture.componentInstance.price = 4500;
fixture.detectChanges();
const divActualPrice = fixture.debugElement.query(By.css('#actualPrice'));
expect(divActualPrice.componentInstance.modifyTotalAmount).toHaveBeenCalled();
});
Normally when parent compoent value get changed this setPrice(price) hits and modifyTotalAmount() function called. But when unit test runs that modifyTotalAmount() not called. this test case get faild. I think what I have done in test case could be wrong. can anyone please clarify whats wrong with this.
Upvotes: 2
Views: 5900
Reputation: 76
As Aniket Kadam already pointed out, when you set
fixture.componentInstance.price = 4500
you are not using the setter setPrice
that you would need to call in order to trigger this.modifyTotalAmount()
So do fixture.componentInstance.setPrice = 4500
instead.
Upvotes: 3