Reputation: 2212
Trying to unit test a getter from an @Input (Angular 5), my test work for the setter (going for 100% code coverage) but I get warnings for the getter
private _triggerOnChange: boolean;
get triggerOnChange(): boolean {
return this._triggerOnChange;
}
@Input()
set triggerOnChange(value: boolean) {
this._triggerOnChange = value;
this.ngOnChanges();
}
This gets me coverage for the setter
it('should', () => {
component.triggerOnChange = true;
expect(component['_triggerOnChange']).toBe(true);
});
But I can't seem to get coverage for the getter
Upvotes: 1
Views: 3586
Reputation: 14201
You are accessing the packing value directly instead of accessing the getter. You should update your test to be:
it('should', () => {
component.triggerOnChange = true;
expect(component['triggerOnChange']).toBe(true);
});
Upvotes: 3