I have this code:
public ngOnInit(): void {
this.searchControl.valueChanges.pipe(debounceTime(300), this.takeUntilDestroyed()).subscribe(query => {
this.officeService.searchQuery = query;
});
}
How to coverage searchQuery setter?
I wrote test who pass, but not coverage setter.
My test:
it('should searchQuery called ', () => {
const { component, service } = setup();
const query: string = 'test';
const fixture: ComponentFixture<SearchComponent> = TestBed.createComponent(SearchComponent);
const input = fixture.debugElement.query(By.css('input'));
const inputEvent = new Event('input');
const spiez: jasmine.Spy = spyOnProperty(service, 'searchQuery', 'set');
component.searchControl.valueChanges.subscribe((tmp: string) => expect(spiez).toHaveBeenCalledWith(tmp));
input.nativeElement.value = 'newString';
input.nativeElement.dispatchEvent(inputEvent);
fixture.detectChanges();
});
Aucun commentaire:
Enregistrer un commentaire