I've got a quick demo people can download here: https://stackblitz.com/edit/angular-vczzqp Just hit export in the top right, in your favourite terminal and run install
and ng test
with your favourite browser.
Basically the issue, to me, seems to be that the internal timings of Jasmine are not matching for the objects.
Below is test as well as the exact error I get. See the example under app/Test for the full test class
it('should return a GET_GENERIC_FAILED when the services throws', () => {
const action = new genericActions.GetAllGenericAction();
genericsService.getAllGenerics.and.returnValue(Observable.throw({}));
actions$.stream = hot('a', { a: action });
const expected = cold('b', { b: new genericActions.GetGenericFailedAction() });
expect(effects.getAllGenerics).toBeObservable(expected);
});
And the error
Expected
[Object({
frame: 0,
notification: Notification({
kind: 'N',
value: GetGenericFailedAction({
type: '[GENERIC] Get Generic Failed'
}),
error: undefined,
hasValue: true
})
}), Object({
frame: 0,
notification: Notification({
kind: 'C',
value: undefined,
error: undefined,
hasValue: false
})
})]
to equal
[Object({
frame: 0,
notification: Notification({
kind: 'N',
value: GetGenericFailedAction({
type: '[GENERIC] Get Generic Failed'
}),
error: undefined,
hasValue: true
})
})].
Any guidance would be appreciated.
It looks like this is an issue over how errors are thrown.
The fix was to add |
to mark the observable as completed as well as to wrap the expected observable in ()
to group the operation together.
actions$.stream = hot('a|', { a|: action });
const expected = cold('(b|)', { b: new genericActions.GetGenericFailedAction() });
Documentation on the syntax is here however the docs for internal maintainers seems a little easier to digest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With