I have angular component where I have something like this:
import { SomeInterface } from '../interfaces';
.....
export class SomeComponent implement OnInit, SomeInterface {
valueUpdated(value: string) {
....
if(value.length === 6) {
this.enterValue = value;
this.submit();
}
}
submit() {
(this as SomeInterface).triggerSomething(true);
.....some other things
}
.
export interface SomeInterface {
....
triggerSometing(value: boolean);
}
.
it('should call valueUpdated', () => {
component.valueUpdated('123456');
fixture.detectChanges();
const submitSpy = spyOn(component, 'submit' as any);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(submitSpy).toHaveBeenCalled();
});
});
And then in unit test when I go throw this function unit test fail: this.triggerSomething is not a function.
How can I fix it, maybe mock this interface in unit test but I do not know how exactly to do that.