jest-marbles icon indicating copy to clipboard operation
jest-marbles copied to clipboard

Bug: Errors are not always compared

Open wandertaker opened this issue 5 years ago • 3 comments

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.

wandertaker avatar Feb 12 '20 08:02 wandertaker

Same issue here with NestJS

pguo-480 avatar Aug 14 '20 08:08 pguo-480

Interesting, thanks for reporting. I'll definitely check it out.

just-jeb avatar Aug 19 '20 07:08 just-jeb

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]));

jBuchholz590 avatar Dec 04 '20 14:12 jBuchholz590

Any updates? The bug is still here. This code passes but it's incorrect.

expect(cold('#', {}, 'A')).toBeObservable(cold('#', {}, 'B'))

solovevserg avatar Dec 20 '23 16:12 solovevserg

Fixed in 3.0.6

just-jeb avatar Dec 25 '23 11:12 just-jeb