0

I am trying to create a simple test with RxJS marbles.

I am using mocha and chai.

I am instantiating a new test scheduler and I do not want to use the "testScheduler.createHotObservable method" because I want to use my own Observable, the "Observable.of(4)"

 const testScheduler = new TestScheduler(assert.deepEqual.bind(assert));

      const expected = "a";
      const expectedStateMap = {
        a: 4
      };

      testScheduler.expectObservable(Observable.of(4)).toBe(expected, expectedStateMap);

      testScheduler.flush();

This is the error:

 AssertionError: expected [ Array(2) ] to deeply equal [ Array(1) ]
      + expected - actual

           "notification": {
             "error": [undefined]
             "hasValue": true
             "kind": "N"
      -      "value": 4
      +      "value": "4"
           }
         }
      -  {
      -    "frame": 0
      -    "notification": {
      -      "error": [undefined]
      -      "hasValue": false
      -      "kind": "C"
      -      "value": [undefined]
      -    }
      -  }
       ]

      at TestScheduler.flush (node_modules/rxjs/src/testing/TestScheduler.ts:135:12)

Any ideas what is wrong?

Dany D
  • 1,189
  • 2
  • 18
  • 44

2 Answers2

1

Yes, it doesn't work. What hot, cold observable creation method does is, creating observable based on given marble and setup internally inside of testscheduler. When testscheduler executes via flush, it iterates all observable and flush. If custom observable is provided, testscheduler doesn't know about existence of those observable and not flush those.

It is just limitation of current testscheduler implementation - unless monkey patch testscheduler to accept custom observable it may not work as expected.

OJ Kwon
  • 4,385
  • 1
  • 20
  • 24
1

You just forgot to complete your Observable.

  const expected = "a";
  const expectedStateMap = {
    a: 4
  };

can be refactored to

  const expected = "4|";
Gerard Sans
  • 2,269
  • 1
  • 13
  • 13