cartant / rxjs-marbles

An RxJS marble testing library for any test framework
https://cartant.github.io/rxjs-marbles/
MIT License
300 stars 18 forks source link

Test Observable that depends on Subject #77

Closed trytuna closed 3 years ago

trytuna commented 3 years ago

I have the following test

  it.only('should test subject', marbles((m) => {
    const subject = new Subject<void>();
    component.validate.next();

    const obs = subject.pipe(
      mapTo('test')
    );
    m.expect(obs).toBeObservable(m.cold('a', { a: 'test' }));
  }));

Sadly it looks like .next does not have any affect in this context.

GroupFormComponent › should test subject

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  - 11
    + Received  +  1

    - Array [
    -   Object {
    -     "frame": 0,
    -     "notification": Notification {
    -       "error": undefined,
    -       "hasValue": true,
    -       "kind": "N",
    -       "value": "test",
    -     },
    -   },
    - ]
    + Array []

      at assertDeepEqual (node_modules/rxjs-marbles/jest/index.js:41:153)
      at Object.observableMatcher (node_modules/rxjs-marbles/matcher.js:38:13)
      at TestScheduler.assertDeepEqual (node_modules/rxjs-marbles/marbles.js:47:38)
      at node_modules/rxjs/src/internal/testing/TestScheduler.ts:159:14
          at Array.filter (<anonymous>)
      at TestScheduler.Object.<anonymous>.TestScheduler.flush (node_modules/rxjs/src/internal/testing/TestScheduler.ts:157:39)
      at TestScheduler.Object.<anonymous>.TestScheduler.run (node_modules/rxjs/src/internal/testing/TestScheduler.ts:392:12)
      at wrapper (node_modules/rxjs-marbles/marbles.js:49:36)
      at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:386:30)
      at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/proxy.js:117:43)
      at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:385:36)
      at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/dist/zone.js:143:47)

Can someone drop me a hint to what I am doing wrong here?

Thanks a lot!

cartant commented 3 years ago

This appears to be a fundamental misunderstanding of how marble testing works and is not an issue with this package. Stack Overflow or the RxJS Gitter would be better forums for seeking help.