As mentioned here if you use
rxjs to implement mock services you can get some unexpected results. In my case, my code always cleans up its subscriptions. But, by default,
of executes synchronously, so the following code will fail because
sub isn’t set when the closure is called.
In order to get this code to behave like a the real service we need to use a scheduler.