My goal is to test the code within an observable subscription:
function bar(someStream$: Observable<number>) {
someStream$.pipe(
map((x) => x + 3),
).subscribe((result) => {
SomeService.someMethod(result)
})
}
I want to ensure that someMethod()
is called with the correct result
. I believe I should be able to achieve this by doing something like
const someStream$ = cold('-a--', { a: 5 })
const someMethodSpy = spyOn(SomeService, 'someMethod')
bar(someStream$)
expect(someMethodSpy).toHaveBeenCalledWith(8)
The issue arises when I am informed that someMethod
was not called. I prefer to keep the stream and subscribe
together in one function.