In a previous post I talked about testing Observables in your Angular code. This is pretty common, because HttpClient sends back an Observable<T> – so if you want to spyOn that function, you’ll need to figure out how to return an Observable.
I’ve been bouncing around a couple of projects/repos recently, and it turns out one of them had upgraded to 6.0.0, which changes how this works.
New Way
Without further ado, here’s how to do it:
What Changed?
Previously, you would import the of operator separately, and it would create it as an extension method on the Observable object.
Now, you just import of and use it as a standalone method.