Jasmine-marbles - Is there a expect(...).ToHaveBeenCalledWithObservable(...) function?

96 views Asked by At

Is there a way to test observable in a function arguments? Is there any thing like expect(someObj.foo).ToHaveBeenCalledWithObservable(cold('a|', {a: 1}))?

1

There are 1 answers

0
AliF50 On BEST ANSWER

I don't think there is something that like that but you can maybe take advantage of callFake and toBeObservable.

We callFake and associate a local variable to the argument that was used.

Then we assert the localVariable toBeObservable of your expecation.

let argumentForFoo: Observable<any>;
spyOn(someObj.foo).and.callFake(argument => argumentForFoo = argument);
// make sure someObj.foo gets called somewhere here so the callFake can run.
expect(argumentForFoo).toBeObservable(/*...*/);