How can I do a simple angular Jasmine Unit testing when using RXJS reactive approach
Here is my simple implementation of the component. I have an items stream that gets some collection of items. Then I have a dropdown in HTML that calls the onSelectItem method which triggers the next() method of the selectedItemSubject. My goal is to test the $itemsWithSelected stream - to check if it returns the correct value - which is influenced by the selected Item and the items stream.
items$ = this.someService.getItems().pipe(
map((items) => {
return items;
})
);
private selectedItemSubject$ = new Subject<any>();
selectionItemAction$ = selectedItemSubject$.asObservable();
$itemsWithSelected = combineLatest([this.selectionItemAction$, items$]).pipe(
map(([selected, items]) => {
var targetItem = items.find(x => x.id === selected);
return someProcess(targetItem.someProperyOfThisItem);
}));
//some method that calls next of the subject
onSelectItem($event){
this.selectedItemSubject$.next($event.value);
}