I want to test my customForm component,which uses component from another library.Firstly i want to test that my component initialized nested library component. Let me show example:
@Component({
selector: 'iris-field-editor',
template `<span>SomeMarkup</span><editorLibrary [init]="init">` ,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => IrisFieldEditorComponent),
multi: true
}
],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class IrisFieldEditorComponent implements OnInit,
ControlValueAccessor {
constructor() {
}
ngOnInit() {
this.init = {
height: '20px',
autoresize_min_height: '20px',
autoresize_max_height: '600px',
someOtherSettings,
setup: (editor) => {
editor.on('focus', (e) => {
//dom manipulation logic
});
editor.on('blur', (e) => {
//dom manipulation logic
});
}
}
}
}
I tried to use spyOn(component.init,'setup');
expect(component.init.setup).toHaveBeenCalled() but got
error: <spyOn> : setup() method does not exist.How can i test method which initialize later in ngOnInit?
Also i wanted to test editor.on functions inside setup function,so mb little advice how can i do this?