Я хочу осветить функцию канала RXJS в Angular / Jasmine.
Я получаю такую ошибку:
TypeError: this.element.children.pipe is not a function
Код:
ngOnInit() {
this.element.children.pipe(
mapObservableArray((children: ObservableTree<ItemModel>) => children.value.properties))
.subscribe((props: Properties[]) => {
// do something with the props or children
this.childrenElements = props as any;
});
}
Это гарантирует, что я могу получить значения дочерних элементов и сохранить их в this.childrenElements.
.spec файл:
import { CommonModule } from '@angular/common';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { myComponent } from './my.component';
describe('myComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CommonModule],
declarations: [myComponent],
providers: [],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
});
it('should create the component', async () => {
const fixture = TestBed.createComponent(myComponent);
const componentInst = fixture.componentInstance;
componentInst.childrenElements = [
{ name: 'name1' },
{ name: 'name2' }
];
// when
componentInst.ngOnInit();
// then
expect(componentInst).toBeDefined();
});
});
Пытался заглушить: spyOn(componentInst.element.children, 'pipe').and.stub();
Но это не помогло.
Как я могу покрыть эту часть моего кода?