spyon
функция выдает ошибку: Expected spy scrollIntoView to have been called
Ниже приведен фрагмент кода компонента:
@Component({
template: `
<form appFocusFirstInvalidField>
<input type="text" class="ng-invalid" onFocus>
<button type="submit"></button>
</form>
`
})
class FocusFirstInvalidInputComponent {
constructor(private el: ElementRef) {
console.log('in constructor');
}
}
Ниже приведен тестовый пример, я добавил функцию spyon для элемента input, но выдает ошибку.
describe('Directive: onFocus', () => {
let fixture: ComponentFixture<FocusFirstInvalidInputComponent>;
let inputEl: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FocusFirstInvalidInputComponent, FocusFirstInvalidFieldDirective]
});
fixture = TestBed.createComponent(FocusFirstInvalidInputComponent);
inputEl = fixture.nativeElement.querySelector('input');
});
it('restrict should paste', () => {
fixture.detectChanges();
const event = new Event('submit', { bubbles: true });
spyOn(inputEl, 'scrollIntoView');
inputEl.dispatchEvent(event);
expect(inputEl.scrollIntoView).toHaveBeenCalled();
});
}); ```