jest-marbles
jest-marbles copied to clipboard
Bug: Errors are not always compared
I'm currently using jest-marbles with typescript in an angular project and encountered a bug in the comparison of errors in marbles. In some cases the errors are just not compared and marbles are asserted as equal even if the errors differ.
Example:
const expectedObservable = hot('^a-#', { a: { test: 1 } }, Error('X'));
const receivedObservable = cold('-a-#', { a: { test: 1 } }, Error('Y'));
expect(receivedObservable).toBeObservable(expectedObservable);
This fails as expected because Error('X')
is not equal to Error('Y')
.
But
const expectedObservable = hot('^#', {}, Error('X'));
const receivedObservable = cold('-#', {}, Error('Y'));
expect(receivedObservable).toBeObservable(expectedObservable);
succeeds even if Error('X')
is not equal to Error('Y')
. I would expect this assertion to fail.
I noticed this also happens if numbers are used emitted instead of objects.
const expectedObservable = hot('^a-#', { a: 1 }, Error('X'));
const receivedObservable = cold('-a-#', { a: 1 }, Error('Y'));
are also equal according to jest-marbles.
Same issue here with NestJS
Interesting, thanks for reporting. I'll definitely check it out.
Any updates on this? I am trying to check the error returned from a function but it always succeeds:
This is the interesting part of my code (the interceptor should extract the errorList returning in just [1, 2, 3]
):
mockHttpHandler = {handle: () => throwError(new HttpErrorResponse({error: {errorList: [1, 2, 3]}}))};
expect(interceptor.intercept({} as any, mockHttpHandler)).toBeObservable(cold('#', null, [4, 5, 6]));
Any updates? The bug is still here. This code passes but it's incorrect.
expect(cold('#', {}, 'A')).toBeObservable(cold('#', {}, 'B'))
Fixed in 3.0.6