Skip to content

Commit

Permalink
feat(output): pretty print marble differences for value objects
Browse files Browse the repository at this point in the history
  • Loading branch information
honsq90 authored and Evgeny Barabanov committed Jun 2, 2018
1 parent 4dfd78f commit 2a29e92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions spec/to-be-observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ describe('toBeObservable matcher test', () => {
expect(a$.pipe(concat(b$))).toBeObservable(expected);
});

it('Should work for value objects', () => {
const valueObject = {foo: 'bar'};
const a$ = cold('-a-|', {a: valueObject});
const expected = cold('-a-|', {a: valueObject});

expect(a$).toBeObservable(expected);
});

it('Should merge two hot observables and start emitting from the subscription point', () => {
const e1 = hot('----a--^--b-------c--|', );
const e2 = hot( '---d-^--e---------f-----|', );
Expand Down
11 changes: 6 additions & 5 deletions src/jest/custom-matchers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Marblizer } from '../marblizer';
import diff from 'jest-diff';
import equal from 'fast-deep-equal';
import { printExpected, printReceived, matcherHint } from 'jest-matcher-utils';
import { TestMessage } from 'rxjs/testing/TestMessage';
import { SubscriptionLog } from 'rxjs/testing/SubscriptionLog';
Expand All @@ -13,18 +14,18 @@ function haveValueObjects(actual: TestMessage[], expected: TestMessage[]) {

export const customTestMatchers = {
toBeNotifications(actual: TestMessage[], expected: TestMessage[]) {
let actualMarble: string;
let expectedMarble: string;
let actualMarble: string | TestMessage[];
let expectedMarble: string | TestMessage[];

if (haveValueObjects(actual, expected)) {
actualMarble = JSON.stringify(actual);
expectedMarble = JSON.stringify(expected);
actualMarble = actual;
expectedMarble = expected;
} else {
actualMarble = Marblizer.marblize(actual);
expectedMarble = Marblizer.marblize(expected);
}

const pass = actualMarble === expectedMarble;
const pass = equal(actualMarble, expectedMarble);

const message = pass
? () =>
Expand Down

0 comments on commit 2a29e92

Please sign in to comment.