Skip to content

Commit

Permalink
test(delay): failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ubnt-michals committed Apr 29, 2018
1 parent b948e65 commit 60e7521
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions spec/operators/delay-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as Rx from 'rxjs/Rx';
import { Observable, timer } from 'rxjs';
import { delay, repeatWhen, skip, take, tap, finalize } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import * as sinon from 'sinon';
import { expect } from 'chai';
import { hot, cold, expectObservable, expectSubscriptions, time } from '../helpers/marble-testing';

declare const asDiagram: Function;
declare const rxTestScheduler: Rx.TestScheduler;
const Observable = Rx.Observable;
declare const rxTestScheduler: TestScheduler;

/** @test {delay} */
describe('Observable.prototype.delay', () => {
Expand Down Expand Up @@ -143,4 +146,33 @@ describe('Observable.prototype.delay', () => {

expectObservable(result).toBe(expected);
});

it('should unsubscribe scheduled action when result is unsubscribed explicitly', () => {
let subscribeSpy: any = null;
const counts: number[] = [];

const e1 = cold('a|');
const expected = '--a-(a|)';
const duration = time('-|');
const result = e1.pipe(
repeatWhen(notifications => {
const delayed = notifications.pipe(delay(duration, rxTestScheduler));
subscribeSpy = sinon.spy(delayed['source'], 'subscribe');
return delayed;
}),
skip(1),
take(2),
tap({
next() {
const [[subscriber]] = subscribeSpy.args;
counts.push(subscriber._subscriptions.length);
},
complete() {
expect(counts).to.deep.equal([1, 1]);
}
})
);

expectObservable(result).toBe(expected);
});
});

0 comments on commit 60e7521

Please sign in to comment.