const action = new fromActions.LoadPosts();
actions$.stream = hot('-a', { a: action });
const expected = cold('-b', { b: completion });
expect(effects.loadPosts$).toBeObservable(expected);
This effect purpose is to activate request in response of "load posts" action:Here is the effect code:
loadPosts$ = this.actions$.ofType(postActions.LOAD_POSTS).pipe(
switchMap(() => {
return this.postService
.getPosts()
.pipe(map(posts => new postActions.LoadPostsSuccess(posts)));
})
);
According to Ben Lesh's explanation here: "observable is cold if its underlying producer is created and activated during the subscription"In our case - the producer is Ajax request to "/post" API.
Since request is NOT made until someone subscribed to it - it considered cold
Unlike "loadPosts" action - which is hot:
export class LoadPosts implements Action {
readonly type = LOAD_POSTS;
}
And here is what the test us checking - is in response to hot action, the cold request is following