hellosmithy / chai-rx

Extends Chai with assertions about RxJS observable streams.
9 stars 4 forks source link

Plugin only works for HotObservable/ColdObservable (created through TestScheduler) #6

Closed djalexd closed 10 months ago

djalexd commented 6 years ago

The following code works without any problems (rxjs5+)

const scheduler = new TestScheduler()
const source = scheduler.createHotScheduler("-a|")
expect(source).to.emit(
  ... message with 'a' value at frame 10 ...,
  ... message with complete at 20 ...
)

However, if there is any kind of operation performed on the source, plugin no longer works. The following code doesn't work:

const scheduler = new TestScheduler()
const source = scheduler.createHotScheduler("-a|").map(x => x)
expect(source).to.emit(
  ... message with 'a' value at frame 10 ...,
  ... message with complete at 20 ...
)

It also fails with very cryptic error message, but in reality the plugin is unable to assert the actual object, because it relies on obj.messages (see https://github.com/hellosmithy/chai-rx/blob/master/src/chai-rx.js#L10) which is no longer defined when chaining.

I don't know how to fix this without a subscription (but even then, tests look ugly).

imho not being able to chain observables severely limits the function of this plugin.

Zeragamba commented 5 years ago

For those ending up here from Google:

A) This is the chai-rx module for RxJS 4. For RxJS 5 and up head on over here: https://github.com/hellosmithy/chai-rx#readme

B) The schedulers aren't supposed to be chained, they are supposed to wrap the observable under test.

let sourceUnderTest = Rx.Observable.from([1,2,3,4]).map(x => x*2);

let scheduler = new Rx.TestScheduler();
testStream$ = scheduler.startScheduler(() => sourceUnderTest);

expect(testStream$).to.emit([
  onNext(200, 2),
  onNext(200, 4),
  onNext(200, 6),
  onNext(200, 8),
  onCompleted(200),
]);
hellosmithy commented 10 months ago

Sorry years late on this, but README now updated to reflect this.