From a1687c37ef70712f7e45ffd9ad93f38b03cac0b5 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Mon, 28 Mar 2016 23:48:37 -0700 Subject: [PATCH] test(ALL): migrate test cases into mocha-chai assertion --- spec/Notification-spec.ts | 77 +- spec/Observable-spec.ts | 188 +-- spec/Scheduler-spec.ts | 16 +- spec/Subject-spec.ts | 147 +-- spec/Subscriber-spec.ts | 25 +- spec/Subscription-spec.ts | 16 +- spec/observables/ErrorObservable-spec.ts | 5 +- spec/observables/IteratorObservable-spec.ts | 74 +- spec/observables/ScalarObservable-spec.ts | 5 +- .../observables/SubscribeOnObservable-spec.ts | 10 +- spec/observables/bindCallback-spec.ts | 45 +- spec/observables/bindNodeCallback-spec.ts | 47 +- spec/observables/combineLatest-spec.ts | 10 +- spec/observables/concat-spec.ts | 7 +- spec/observables/defer-spec.ts | 18 +- spec/observables/dom/ajax-spec.ts | 103 +- spec/observables/dom/webSocket-spec.ts | 98 +- spec/observables/forkJoin-spec.ts | 11 +- spec/observables/from-promise-spec.ts | 123 +- spec/observables/from-spec.ts | 85 +- spec/observables/fromEvent-spec.ts | 56 +- spec/observables/fromEventPattern-spec.ts | 23 +- spec/observables/if-spec.ts | 35 +- spec/observables/interval-spec.ts | 18 +- spec/observables/merge-spec.ts | 3 +- spec/observables/of-spec.ts | 32 +- spec/observables/range-spec.ts | 47 +- spec/observables/throw-spec.ts | 10 +- spec/observables/timer-spec.ts | 2 +- spec/observables/using-spec.ts | 36 +- spec/observables/zip-spec.ts | 12 +- spec/operators/audit-spec.ts | 20 +- spec/operators/auditTime-spec.ts | 8 +- spec/operators/bufferToggle-spec.ts | 3 +- spec/operators/bufferWhen-spec.ts | 10 +- spec/operators/catch-spec.ts | 8 +- spec/operators/combineAll-spec.ts | 14 +- spec/operators/concat-spec.ts | 8 +- spec/operators/concatAll-spec.ts | 23 +- spec/operators/concatMap-spec.ts | 46 +- spec/operators/concatMapTo-spec.ts | 32 +- spec/operators/count-spec.ts | 20 +- spec/operators/debounce-spec.ts | 20 +- spec/operators/do-spec.ts | 42 +- spec/operators/elementAt-spec.ts | 3 +- spec/operators/every-spec.ts | 7 +- spec/operators/exhaust-spec.ts | 16 +- spec/operators/expand-spec.ts | 20 +- spec/operators/filter-spec.ts | 12 +- spec/operators/finally-spec.ts | 18 +- spec/operators/find-spec.ts | 3 +- spec/operators/first-spec.ts | 5 +- spec/operators/groupBy-spec.ts | 34 +- spec/operators/last-spec.ts | 5 +- spec/operators/let-spec.ts | 8 +- spec/operators/map-spec.ts | 21 +- spec/operators/mapTo-spec.ts | 3 +- spec/operators/max-spec.ts | 20 +- spec/operators/merge-spec.ts | 22 +- spec/operators/mergeAll-spec.ts | 18 +- spec/operators/mergeMap-spec.ts | 60 +- spec/operators/mergeMapTo-spec.ts | 46 +- spec/operators/min-spec.ts | 20 +- spec/operators/multicast-spec.ts | 1152 ++++++++--------- spec/operators/partition-spec.ts | 3 +- spec/operators/pluck-spec.ts | 5 +- spec/operators/publish-spec.ts | 44 +- spec/operators/publishBehavior-spec.ts | 49 +- spec/operators/publishLast-spec.ts | 16 +- spec/operators/publishReplay-spec.ts | 782 ++++++----- spec/operators/refCount-spec.ts | 12 +- spec/operators/repeat-spec.ts | 18 +- spec/operators/retry-spec.ts | 32 +- spec/operators/retryWhen-spec.ts | 18 +- spec/operators/share-spec.ts | 5 +- spec/operators/skipWhile-spec.ts | 3 +- spec/operators/switch-spec.ts | 32 +- spec/operators/switchMap-spec.ts | 8 +- spec/operators/switchMapTo-spec.ts | 8 +- spec/operators/take-spec.ts | 3 +- spec/operators/takeLast-spec.ts | 3 +- spec/operators/takeWhile-spec.ts | 3 +- spec/operators/throttle-spec.ts | 20 +- spec/operators/throttleTime-spec.ts | 8 +- spec/operators/toPromise-spec.ts | 18 +- spec/operators/window-spec.ts | 3 +- spec/operators/windowCount-spec.ts | 3 +- spec/operators/windowTime-spec.ts | 3 +- spec/operators/windowToggle-spec.ts | 5 +- spec/operators/windowWhen-spec.ts | 3 +- spec/operators/withLatestFrom-spec.ts | 11 +- spec/operators/zip-spec.ts | 12 +- spec/operators/zipAll-spec.ts | 20 +- spec/root-module-spec.ts | 3 +- spec/schedulers/AsapScheduler-spec.ts | 14 +- spec/schedulers/TestScheduler-spec.ts | 84 +- spec/schedulers/VirtualTimeScheduler-spec.ts | 16 +- spec/subjects/AsyncSubject-spec.ts | 51 +- spec/subjects/BehaviorSubject-spec.ts | 58 +- spec/subjects/ReplaySubject-spec.ts | 40 +- spec/symbol/iterator-spec.ts | 12 +- spec/symbol/observable-spec.ts | 7 +- spec/symbol/rxSubscriber-spec.ts | 5 +- spec/util/FastMap-spec.ts | 29 +- spec/util/Immediate-spec.ts | 333 ++--- spec/util/MapPolyfill-spec.ts | 33 +- 106 files changed, 2527 insertions(+), 2439 deletions(-) diff --git a/spec/Notification-spec.ts b/spec/Notification-spec.ts index e4a737e2e8..f4e26028f4 100644 --- a/spec/Notification-spec.ts +++ b/spec/Notification-spec.ts @@ -1,45 +1,46 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; -declare const expectObservable; +declare const expectObservable; const Notification = Rx.Notification; /** @test {Notification} */ describe('Notification', () => { it('should exist', () => { - expect(Notification).toBeDefined(); - expect(typeof Notification).toBe('function'); + expect(Notification).exist; + expect(Notification).to.be.a('function'); }); describe('createNext', () => { it('should return a Notification', () => { const n = Notification.createNext('test'); - expect(n instanceof Notification).toBe(true); - expect(n.value).toBe('test'); - expect(n.kind).toBe('N'); - expect(typeof n.exception).toBe('undefined'); - expect(n.hasValue).toBe(true); + expect(n instanceof Notification).to.be.true; + expect(n.value).to.equal('test'); + expect(n.kind).to.equal('N'); + expect(n.exception).to.be.a('undefined'); + expect(n.hasValue).to.be.true; }); }); describe('createError', () => { it('should return a Notification', () => { const n = Notification.createError('test'); - expect(n instanceof Notification).toBe(true); - expect(typeof n.value).toBe('undefined'); - expect(n.kind).toBe('E'); - expect(n.exception).toBe('test'); - expect(n.hasValue).toBe(false); + expect(n instanceof Notification).to.be.true; + expect(n.value).to.be.a('undefined'); + expect(n.kind).to.equal('E'); + expect(n.exception).to.equal('test'); + expect(n.hasValue).to.be.false; }); }); describe('createComplete', () => { it('should return a Notification', () => { const n = Notification.createComplete(); - expect(n instanceof Notification).toBe(true); - expect(typeof n.value).toBe('undefined'); - expect(n.kind).toBe('C'); - expect(typeof n.exception).toBe('undefined'); - expect(n.hasValue).toBe(false); + expect(n instanceof Notification).to.be.true; + expect(n.value).to.be.a('undefined'); + expect(n.kind).to.equal('C'); + expect(n.exception).to.be.a('undefined'); + expect(n.hasValue).to.be.false; }); }); @@ -67,28 +68,28 @@ describe('Notification', () => { const first = Notification.createNext(value); const second = Notification.createNext(value); - expect(first).not.toBe(second); + expect(first).not.to.equal(second); }); it('should create new error Notification', () => { const first = Notification.createError(); const second = Notification.createError(); - expect(first).not.toBe(second); + expect(first).not.to.equal(second); }); it('should return static next Notification reference without value', () => { const first = Notification.createNext(undefined); const second = Notification.createNext(undefined); - expect(first).toBe(second); + expect(first).to.equal(second); }); it('should return static complete Notification reference', () => { const first = Notification.createComplete(); const second = Notification.createComplete(); - expect(first).toBe(second); + expect(first).to.equal(second); }); }); @@ -104,7 +105,7 @@ describe('Notification', () => { throw 'should not be called'; }); - expect(invoked).toBe(true); + expect(invoked).to.be.true; }); it('should invoke on error', () => { @@ -118,7 +119,7 @@ describe('Notification', () => { throw 'should not be called'; }); - expect(invoked).toBe(true); + expect(invoked).to.be.true; }); it('should invoke on complete', () => { @@ -132,7 +133,7 @@ describe('Notification', () => { invoked = true; }); - expect(invoked).toBe(true); + expect(invoked).to.be.true; }); }); @@ -142,7 +143,7 @@ describe('Notification', () => { let observed = false; const n = Notification.createNext(value); const observer = Rx.Subscriber.create((x: string) => { - expect(x).toBe(value); + expect(x).to.equal(value); observed = true; }, (err: any) => { throw 'should not be called'; @@ -151,7 +152,7 @@ describe('Notification', () => { }); n.accept(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should accept observer for error Notification', () => { @@ -166,7 +167,7 @@ describe('Notification', () => { }); n.accept(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should accept observer for complete Notification', () => { @@ -181,7 +182,7 @@ describe('Notification', () => { }); n.accept(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should accept function for next Notification', () => { @@ -190,14 +191,14 @@ describe('Notification', () => { const n = Notification.createNext(value); n.accept((x: string) => { - expect(x).toBe(value); + expect(x).to.equal(value); observed = true; }, (err: any) => { throw 'should not be called'; }, () => { throw 'should not be called'; }); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should accept function for error Notification', () => { @@ -208,12 +209,12 @@ describe('Notification', () => { n.accept((x: any) => { throw 'should not be called'; }, (err: any) => { - expect(err).toBe(error); + expect(err).to.equal(error); observed = true; }, () => { throw 'should not be called'; }); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should accept function for complete Notification', () => { @@ -227,7 +228,7 @@ describe('Notification', () => { }, () => { observed = true; }); - expect(observed).toBe(true); + expect(observed).to.be.true; }); }); @@ -237,7 +238,7 @@ describe('Notification', () => { let observed = false; const n = Notification.createNext(value); const observer = Rx.Subscriber.create((x: string) => { - expect(x).toBe(value); + expect(x).to.equal(value); observed = true; }, (err: any) => { throw 'should not be called'; @@ -246,7 +247,7 @@ describe('Notification', () => { }); n.observe(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should observe for error Notification', () => { @@ -261,7 +262,7 @@ describe('Notification', () => { }); n.observe(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); it('should observe for complete Notification', () => { @@ -276,7 +277,7 @@ describe('Notification', () => { }); n.observe(observer); - expect(observed).toBe(true); + expect(observed).to.be.true; }); }); }); diff --git a/spec/Observable-spec.ts b/spec/Observable-spec.ts index 34e1cc007b..8f29c29dcc 100644 --- a/spec/Observable-spec.ts +++ b/spec/Observable-spec.ts @@ -1,5 +1,5 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; -import {DoneSignature} from './helpers/test-helper'; const Subscriber = Rx.Subscriber; const Observable = Rx.Observable; @@ -7,48 +7,50 @@ const Observable = Rx.Observable; declare const __root__: any; function expectFullObserver(val) { - expect(typeof val).toBe('object'); - expect(typeof val.next).toBe('function'); - expect(typeof val.error).toBe('function'); - expect(typeof val.complete).toBe('function'); - expect(typeof val.isUnsubscribed).toBe('boolean'); + expect(val).to.be.a('object'); + expect(val.next).to.be.a('function'); + expect(val.error).to.be.a('function'); + expect(val.complete).to.be.a('function'); + expect(val.isUnsubscribed).to.be.a('boolean'); } /** @test {Observable} */ describe('Observable', () => { - it('should be constructed with a subscriber function', (done: DoneSignature) => { + it('should be constructed with a subscriber function', (done: MochaDone) => { const source = new Observable(function (observer) { expectFullObserver(observer); observer.next(1); observer.complete(); }); - source.subscribe(function (x) { expect(x).toBe(1); }, null, done); + source.subscribe(function (x) { expect(x).to.equal(1); }, null, done); }); describe('forEach', () => { - it('should iterate and return a Promise', (done: DoneSignature) => { + it('should iterate and return a Promise', (done: MochaDone) => { const expected = [1, 2, 3]; const result = Observable.of(1, 2, 3).forEach(function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, Promise) - .then(done); + .then(() => { + done(); + }); - expect(typeof result.then).toBe('function'); + expect(result.then).to.be.a('function'); }); - it('should reject promise when in error', (done: DoneSignature) => { + it('should reject promise when in error', (done: MochaDone) => { Observable.throw('bad').forEach((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, Promise).then(() => { - done.fail('should not complete'); + done(new Error('should not complete')); }, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); done(); }); }); - it('should allow Promise to be globally configured', (done: DoneSignature) => { + it('should allow Promise to be globally configured', (done: MochaDone) => { let wasCalled = false; __root__.Rx = {}; @@ -59,29 +61,33 @@ describe('Observable', () => { }; Observable.of(42).forEach((x: number) => { - expect(x).toBe(42); - }, null).then(() => { - expect(wasCalled).toBe(true); + expect(x).to.equal(42); + }).then(() => { + expect(wasCalled).to.be.true; done(); }); }); - it('should reject promise if nextHandler throws', (done: DoneSignature) => { + it('should reject promise if nextHandler throws', (done: MochaDone) => { const results = []; + Observable.of(1, 2, 3).forEach((x: number) => { if (x === 3) { throw new Error('NO THREES!'); } results.push(x); - }, null) - .then(done.fail, function (err) { - expect(err).toEqual(new Error('NO THREES!')); - expect(results).toEqual([1, 2]); - }) - .then(done); + }, Promise) + .then(() => { + done(new Error('should not be called')); + }, (err) => { + expect(err).to.be.an('error', 'NO THREES!'); + expect(results).to.deep.equal([1, 2]); + }).then(() => { + done(); + }); }); - it('should handle a synchronous throw from the next handler and tear down', (done: DoneSignature) => { + it('should handle a synchronous throw from the next handler and tear down', (done: MochaDone) => { let unsubscribeCalled = false; const syncObservable = new Observable((observer: Rx.Observer) => { observer.next(1); @@ -100,16 +106,18 @@ describe('Observable', () => { throw new Error('I told, you Bobby Boucher, twos are the debil!'); } }).then( - () => done.fail(), + () => { + done(new Error('should not be called')); + }, (err) => { results.push(err); - expect(results).toEqual([1, 2, new Error('I told, you Bobby Boucher, twos are the debil!')]); - expect(unsubscribeCalled).toBe(true); + expect(results).to.deep.equal([1, 2, new Error('I told, you Bobby Boucher, twos are the debil!')]); + expect(unsubscribeCalled).to.be.true; done(); }); }); - it('should handle an asynchronous throw from the next handler and tear down', (done: DoneSignature) => { + it('should handle an asynchronous throw from the next handler and tear down', (done: MochaDone) => { let unsubscribeCalled = false; const syncObservable = new Observable((observer: Rx.Observer) => { let i = 1; @@ -128,11 +136,13 @@ describe('Observable', () => { throw new Error('I told, you Bobby Boucher, twos are the debil!'); } }).then( - () => done.fail(), + () => { + done(new Error('should not be called')); + }, (err) => { results.push(err); - expect(results).toEqual([1, 2, new Error('I told, you Bobby Boucher, twos are the debil!')]); - expect(unsubscribeCalled).toBe(true); + expect(results).to.deep.equal([1, 2, new Error('I told, you Bobby Boucher, twos are the debil!')]); + expect(unsubscribeCalled).to.be.true; done(); }); }); @@ -146,12 +156,12 @@ describe('Observable', () => { const source = new Observable((observer: Rx.Observer) => { subscribed = true; observer.next('wee'); - expect(nexted).toBe('wee'); + expect(nexted).to.equal('wee'); observer.complete(); - expect(completed).toBe(true); + expect(completed).to.be.true; }); - expect(subscribed).toBe(false); + expect(subscribed).to.be.false; let mutatedByNext = false; let mutatedByComplete = false; @@ -164,8 +174,8 @@ describe('Observable', () => { mutatedByComplete = true; }); - expect(mutatedByNext).toBe(true); - expect(mutatedByComplete).toBe(true); + expect(mutatedByNext).to.be.true; + expect(mutatedByComplete).to.be.true; }); it('should work when subscribe is called with no arguments', () => { @@ -189,12 +199,12 @@ describe('Observable', () => { const sub = source.subscribe(() => { //noop }); - expect(sub instanceof Rx.Subscription).toBe(true); - expect(unsubscribeCalled).toBe(false); - expect(typeof sub.unsubscribe).toBe('function'); + expect(sub instanceof Rx.Subscription).to.be.true; + expect(unsubscribeCalled).to.be.false; + expect(sub.unsubscribe).to.be.a('function'); sub.unsubscribe(); - expect(unsubscribeCalled).toBe(true); + expect(unsubscribeCalled).to.be.true; }); it('should run unsubscription logic when an error is thrown sending messages synchronously', () => { @@ -217,10 +227,10 @@ describe('Observable', () => { messageErrorValue = e; } - expect(sub).toBe(undefined); - expect(unsubscribeCalled).toBe(true); - expect(messageError).toBe(true); - expect(messageErrorValue).toBe('boo!'); + expect(sub).to.be.a('undefined'); + expect(unsubscribeCalled).to.be.true; + expect(messageError).to.be.true; + expect(messageErrorValue).to.equal('boo!'); }); it('should dispose of the subscriber when an error is thrown sending messages synchronously', () => { @@ -244,11 +254,11 @@ describe('Observable', () => { messageErrorValue = e; } - expect(sub).toBe(undefined); - expect(subscriber.isUnsubscribed).toBe(true); - expect(unsubscribeCalled).toBe(true); - expect(messageError).toBe(true); - expect(messageErrorValue).toBe('boo!'); + expect(sub).to.be.a('undefined'); + expect(subscriber.isUnsubscribed).to.be.true; + expect(unsubscribeCalled).to.be.true; + expect(messageError).to.be.true; + expect(messageErrorValue).to.equal('boo!'); }); it('should ignore next messages after unsubscription', () => { @@ -269,7 +279,7 @@ describe('Observable', () => { } ); - expect(times).toBe(2); + expect(times).to.equal(2); }); it('should ignore error messages after unsubscription', () => { @@ -292,8 +302,8 @@ describe('Observable', () => { function() { errorCalled = true; } ); - expect(times).toBe(2); - expect(errorCalled).toBe(false); + expect(times).to.equal(2); + expect(errorCalled).to.be.false; }); it('should ignore complete messages after unsubscription', () => { @@ -317,18 +327,18 @@ describe('Observable', () => { function() { completeCalled = true; } ); - expect(times).toBe(2); - expect(completeCalled).toBe(false); + expect(times).to.equal(2); + expect(completeCalled).to.be.false; }); describe('when called with an anonymous observer', () => { it('should accept an anonymous observer with just a next function and call the next function in the context' + - ' of the anonymous observer', (done: DoneSignature) => { + ' of the anonymous observer', (done: MochaDone) => { //intentionally not using lambda to avoid typescript's this context capture const o = { next: function next(x) { - expect(this).toBe(o); - expect(x).toBe(1); + expect(this).to.equal(o); + expect(x).to.equal(1); done(); } }; @@ -337,12 +347,12 @@ describe('Observable', () => { }); it('should accept an anonymous observer with just an error function and call the error function in the context' + - ' of the anonymous observer', (done: DoneSignature) => { + ' of the anonymous observer', (done: MochaDone) => { //intentionally not using lambda to avoid typescript's this context capture const o = { error: function error(err) { - expect(this).toBe(o); - expect(err).toBe('bad'); + expect(this).to.equal(o); + expect(err).to.equal('bad'); done(); } }; @@ -351,11 +361,11 @@ describe('Observable', () => { }); it('should accept an anonymous observer with just a complete function and call the complete function in the' + - ' context of the anonymous observer', (done: DoneSignature) => { + ' context of the anonymous observer', (done: MochaDone) => { //intentionally not using lambda to avoid typescript's this context capture const o = { complete: function complete() { - expect(this).toBe(o); + expect(this).to.equal(o); done(); } }; @@ -366,7 +376,7 @@ describe('Observable', () => { it('should accept an anonymous observer with no functions at all', () => { expect(() => { Observable.empty().subscribe({}); - }).not.toThrow(); + }).not.to.throw(); }); it('should run unsubscription logic when an error is thrown sending messages synchronously to an' + @@ -378,7 +388,7 @@ describe('Observable', () => { //intentionally not using lambda to avoid typescript's this context capture const o = { next: function next(x) { - expect(this).toBe(o); + expect(this).to.equal(o); throw x; } }; @@ -398,10 +408,10 @@ describe('Observable', () => { messageErrorValue = e; } - expect(sub).toBe(undefined); - expect(unsubscribeCalled).toBe(true); - expect(messageError).toBe(true); - expect(messageErrorValue).toBe('boo!'); + expect(sub).to.be.a('undefined'); + expect(unsubscribeCalled).to.be.true; + expect(messageError).to.be.true; + expect(messageErrorValue).to.equal('boo!'); }); it('should ignore next messages after unsubscription', () => { @@ -422,7 +432,7 @@ describe('Observable', () => { } }); - expect(times).toBe(2); + expect(times).to.equal(2); }); it('should ignore error messages after unsubscription', () => { @@ -445,8 +455,8 @@ describe('Observable', () => { error() { errorCalled = true; } }); - expect(times).toBe(2); - expect(errorCalled).toBe(false); + expect(times).to.equal(2); + expect(errorCalled).to.be.false; }); it('should ignore complete messages after unsubscription', () => { @@ -469,8 +479,8 @@ describe('Observable', () => { complete() { completeCalled = true; } }); - expect(times).toBe(2); - expect(completeCalled).toBe(false); + expect(times).to.equal(2); + expect(completeCalled).to.be.false; }); }); }); @@ -482,7 +492,7 @@ describe('Observable.create', () => { const result = Observable.create(() => { //noop }); - expect(result instanceof Observable).toBe(true); + expect(result instanceof Observable).to.be.true; }); it('should provide an observer to the function', () => { @@ -493,17 +503,17 @@ describe('Observable.create', () => { observer.complete(); }); - expect(called).toBe(false); + expect(called).to.be.false; result.subscribe(() => { //noop }); - expect(called).toBe(true); + expect(called).to.be.true; }); }); /** @test {Observable} */ describe('Observable.lift', () => { - it('should be overrideable in a custom Observable type that composes', (done: DoneSignature) => { + it('should be overrideable in a custom Observable type that composes', (done: MochaDone) => { class MyCustomObservable extends Rx.Observable { lift(operator: Rx.Operator): Rx.Observable { const observable = new MyCustomObservable(); @@ -520,22 +530,22 @@ describe('Observable.lift', () => { observer.complete(); }).map((x: number) => { return 10 * x; }); - expect(result instanceof MyCustomObservable).toBe(true); + expect(result instanceof MyCustomObservable).to.be.true; const expected = [10, 20, 30]; result.subscribe( function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); it('should allow injecting behaviors into all subscribers in an operator ' + - 'chain when overridden', (done: DoneSignature) => { + 'chain when overridden', (done: MochaDone) => { // The custom Subscriber const log: Array = []; @@ -580,18 +590,18 @@ describe('Observable.lift', () => { .filter((x: number) => { return x > 15; }) .count(); - expect(result instanceof LogObservable).toBe(true); + expect(result instanceof LogObservable).to.be.true; const expected = [2]; result.subscribe( function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(log).toEqual([ + expect(log).to.deep.equal([ 'next 10', // map 'next 20', // map 'next 20', // filter diff --git a/spec/Scheduler-spec.ts b/spec/Scheduler-spec.ts index d220f35faf..c47bc2fe33 100644 --- a/spec/Scheduler-spec.ts +++ b/spec/Scheduler-spec.ts @@ -1,5 +1,5 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; -import {DoneSignature} from './helpers/test-helper'; const Scheduler = Rx.Scheduler; @@ -15,27 +15,27 @@ describe('Scheduler.queue', () => { call2 = true; }); }); - expect(call1).toBe(true); - expect(call2).toBe(true); + expect(call1).to.be.true; + expect(call2).to.be.true; }); - it('should schedule things in the future too', (done: DoneSignature) => { + it('should schedule things in the future too', (done: MochaDone) => { let called = false; Scheduler.queue.schedule(() => { called = true; }, 50); setTimeout(() => { - expect(called).toBe(false); + expect(called).to.be.false; }, 40); setTimeout(() => { - expect(called).toBe(true); + expect(called).to.be.true; done(); }, 70); }); - it('should be reusable after an error is thrown during execution', (done: DoneSignature) => { + it('should be reusable after an error is thrown during execution', (done: MochaDone) => { const results = []; expect(() => { @@ -46,7 +46,7 @@ describe('Scheduler.queue', () => { Scheduler.queue.schedule(() => { throw new Error('bad'); }); - }).toThrow(new Error('bad')); + }).to.throw(Error, 'bad'); setTimeout(() => { Scheduler.queue.schedule(() => { diff --git a/spec/Subject-spec.ts b/spec/Subject-spec.ts index d4e4bff135..5954d5ab1e 100644 --- a/spec/Subject-spec.ts +++ b/spec/Subject-spec.ts @@ -1,18 +1,19 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; + declare const {hot, expectObservable}; -import {DoneSignature} from './helpers/test-helper'; const Subject = Rx.Subject; const Observable = Rx.Observable; /** @test {Subject} */ describe('Subject', () => { - it('should pump values right on through itself', (done: DoneSignature) => { + it('should pump values right on through itself', (done: MochaDone) => { const subject = new Subject(); const expected = ['foo', 'bar']; subject.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, done); subject.next('foo'); @@ -22,10 +23,10 @@ describe('Subject', () => { it('should have the rxSubscriber Symbol', () => { const subject = new Subject(); - expect(typeof subject[Rx.Symbol.rxSubscriber]).toBe('function'); + expect(subject[Rx.Symbol.rxSubscriber]).to.be.a('function'); }); - it('should pump values to multiple subscribers', (done: DoneSignature) => { + it('should pump values to multiple subscribers', (done: MochaDone) => { const subject = new Subject(); const expected = ['foo', 'bar']; @@ -33,14 +34,14 @@ describe('Subject', () => { let j = 0; subject.subscribe(function (x) { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }); subject.subscribe(function (x) { - expect(x).toBe(expected[j++]); + expect(x).to.equal(expected[j++]); }, null, done); - expect(subject.observers.length).toBe(2); + expect(subject.observers.length).to.equal(2); subject.next('foo'); subject.next('bar'); subject.complete(); @@ -94,9 +95,9 @@ describe('Subject', () => { subscription3.unsubscribe(); - expect(results1).toEqual([5, 6, 7]); - expect(results2).toEqual([6, 7, 8]); - expect(results3).toEqual([11]); + expect(results1).to.deep.equal([5, 6, 7]); + expect(results2).to.deep.equal([6, 7, 8]); + expect(results3).to.deep.equal([11]); }); it('should handle subscribers that arrive and leave at different times, ' + @@ -142,9 +143,9 @@ describe('Subject', () => { subscription3.unsubscribe(); - expect(results1).toEqual([5, 6, 7]); - expect(results2).toEqual([6, 7, 'C']); - expect(results3).toEqual(['C']); + expect(results1).to.deep.equal([5, 6, 7]); + expect(results2).to.deep.equal([6, 7, 'C']); + expect(results3).to.deep.equal(['C']); }); it('should handle subscribers that arrive and leave at different times, ' + @@ -190,9 +191,9 @@ describe('Subject', () => { subscription3.unsubscribe(); - expect(results1).toEqual([5, 6, 7]); - expect(results2).toEqual([6, 7, 'E']); - expect(results3).toEqual(['E']); + expect(results1).to.deep.equal([5, 6, 7]); + expect(results2).to.deep.equal([6, 7, 'E']); + expect(results3).to.deep.equal(['E']); }); it('should handle subscribers that arrive and leave at different times, ' + @@ -228,9 +229,9 @@ describe('Subject', () => { subscription3.unsubscribe(); - expect(results1).toEqual([]); - expect(results2).toEqual(['C']); - expect(results3).toEqual(['C']); + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal(['C']); + expect(results3).to.deep.equal(['C']); }); it('should disallow new subscriber once subject has been disposed', () => { @@ -268,11 +269,11 @@ describe('Subject', () => { function (e) { results3.push('E'); }, () => { results3.push('C'); } ); - }).toThrow(); + }).to.throw(); - expect(results1).toEqual([1, 2, 3, 4, 5]); - expect(results2).toEqual([3, 4, 5]); - expect(results3).toEqual([]); + expect(results1).to.deep.equal([1, 2, 3, 4, 5]); + expect(results2).to.deep.equal([3, 4, 5]); + expect(results3).to.deep.equal([]); }); it('should allow ad-hoc subscription to be added to itself', () => { @@ -307,9 +308,9 @@ describe('Subject', () => { auxSubject.next('c'); auxSubject.next('d'); - expect(results1).toEqual([1, 2, 3]); - expect(subscription2.isUnsubscribed).toBe(true); - expect(results2).toEqual(['a', 'b']); + expect(results1).to.deep.equal([1, 2, 3]); + expect(subscription2.isUnsubscribed).to.be.true; + expect(results2).to.deep.equal(['a', 'b']); }); it('should allow ad-hoc subscription to be removed from itself', () => { @@ -345,26 +346,26 @@ describe('Subject', () => { auxSubject.next('c'); auxSubject.next('d'); - expect(results1).toEqual([1, 2, 3]); - expect(subscription2.isUnsubscribed).toBe(false); - expect(results2).toEqual(['a', 'b', 'c', 'd']); + expect(results1).to.deep.equal([1, 2, 3]); + expect(subscription2.isUnsubscribed).to.be.false; + expect(results2).to.deep.equal(['a', 'b', 'c', 'd']); }); - it('should not allow values to be nexted after a return', (done: DoneSignature) => { + it('should not allow values to be nexted after a return', (done: MochaDone) => { const subject = new Subject(); const expected = ['foo']; subject.subscribe(function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }); subject.next('foo'); subject.complete(); - expect(() => subject.next('bar')).toThrow(new Rx.ObjectUnsubscribedError()); + expect(() => subject.next('bar')).to.throw(Rx.ObjectUnsubscribedError); done(); }); - it('should clean out unsubscribed subscribers', (done: DoneSignature) => { + it('should clean out unsubscribed subscribers', (done: MochaDone) => { const subject = new Subject(); const sub1 = subject.subscribe(function (x) { @@ -375,16 +376,16 @@ describe('Subject', () => { //noop }); - expect(subject.observers.length).toBe(2); + expect(subject.observers.length).to.equal(2); sub1.unsubscribe(); - expect(subject.observers.length).toBe(1); + expect(subject.observers.length).to.equal(1); sub2.unsubscribe(); - expect(subject.observers.length).toBe(0); + expect(subject.observers.length).to.equal(0); done(); }); it('should have a static create function that works', () => { - expect(typeof Subject.create).toBe('function'); + expect(Subject.create).to.be.a('function'); const source = Observable.of(1, 2, 3, 4, 5); const nexts = []; const output = []; @@ -421,16 +422,16 @@ describe('Subject', () => { sub.next('c'); sub.complete(); - expect(nexts).toEqual(['a', 'b', 'c']); - expect(complete).toBe(true); - expect(error).toBe(undefined); + expect(nexts).to.deep.equal(['a', 'b', 'c']); + expect(complete).to.be.true; + expect(error).to.be.a('undefined'); - expect(output).toEqual([1, 2, 3, 4, 5]); - expect(outputComplete).toBe(true); + expect(output).to.deep.equal([1, 2, 3, 4, 5]); + expect(outputComplete).to.be.true; }); it('should have a static create function that works also to raise errors', () => { - expect(typeof Subject.create).toBe('function'); + expect(Subject.create).to.be.a('function'); const source = Observable.of(1, 2, 3, 4, 5); const nexts = []; const output = []; @@ -467,24 +468,24 @@ describe('Subject', () => { sub.next('c'); sub.error('boom'); - expect(nexts).toEqual(['a', 'b', 'c']); - expect(complete).toBe(false); - expect(error).toBe('boom'); + expect(nexts).to.deep.equal(['a', 'b', 'c']); + expect(complete).to.be.false; + expect(error).to.equal('boom'); - expect(output).toEqual([1, 2, 3, 4, 5]); - expect(outputComplete).toBe(true); + expect(output).to.deep.equal([1, 2, 3, 4, 5]); + expect(outputComplete).to.be.true; }); - it('should be an Observer which can be given to Observable.subscribe', (done: DoneSignature) => { + it('should be an Observer which can be given to Observable.subscribe', (done: MochaDone) => { const source = Observable.of(1, 2, 3, 4, 5); const subject = new Subject(); const expected = [1, 2, 3, 4, 5]; subject.subscribe( function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -492,7 +493,7 @@ describe('Subject', () => { source.subscribe(subject); }); - it('should be usable as an Observer of a finite delayed Observable', (done: DoneSignature) => { + it('should be usable as an Observer of a finite delayed Observable', (done: MochaDone) => { const source = Rx.Observable.of(1, 2, 3).delay(50); const subject = new Rx.Subject(); @@ -500,9 +501,9 @@ describe('Subject', () => { subject.subscribe( function (x) { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -516,15 +517,15 @@ describe('Subject', () => { expect(() => { subject.next('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.error('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.complete(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }); it('should throw ObjectUnsubscribedError when emit after completed', () => { @@ -533,15 +534,15 @@ describe('Subject', () => { expect(() => { subject.next('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.error('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.complete(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }); it('should throw ObjectUnsubscribedError when emit after error', () => { @@ -550,15 +551,15 @@ describe('Subject', () => { expect(() => { subject.next('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.error('a'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); expect(() => { subject.complete(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }); describe('asObservable', () => { @@ -566,10 +567,10 @@ describe('Subject', () => { const subject = new Rx.Subject(); const observable = subject.asObservable(); - expect(subject).not.toEqual(observable); + expect(subject).not.to.equal(observable); - expect(observable instanceof Observable).toBe(true); - expect(observable instanceof Subject).toBe(false); + expect(observable instanceof Observable).to.be.true; + expect(observable instanceof Subject).to.be.false; }); it('should handle subject never emits', () => { @@ -599,7 +600,7 @@ describe('Subject', () => { expectObservable(observable).toBe(expected); }); - it('should work with inherited subject', (done: DoneSignature) => { + it('should work with inherited subject', (done: MochaDone) => { const subject = new Rx.AsyncSubject(); subject.next(42); @@ -611,11 +612,11 @@ describe('Subject', () => { new Rx.Notification('C')]; observable.materialize().subscribe((x: Rx.Notification) => { - expect(x).toEqual(expected.shift()); + expect(x).to.deep.equal(expected.shift()); }, (err: any) => { - done.fail(err); + done(err); }, () => { - expect(expected).toEqual([]); + expect(expected).to.deep.equal([]); done(); }); }); @@ -632,10 +633,10 @@ describe('Subject', () => { })); const observable = subject.asObservable(); - expect(subscribed).toBe(false); + expect(subscribed).to.be.false; observable.subscribe(); - expect(subscribed).toBe(true); + expect(subscribed).to.be.true; }); }); }); diff --git a/spec/Subscriber-spec.ts b/spec/Subscriber-spec.ts index b1163683bf..d2efa0a249 100644 --- a/spec/Subscriber-spec.ts +++ b/spec/Subscriber-spec.ts @@ -1,17 +1,20 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../dist/cjs/Rx'; + const Subscriber = Rx.Subscriber; /** @test {Subscriber} */ describe('Subscriber', () => { it('should have the rxSubscriber symbol', () => { const sub = new Subscriber(); - expect(sub[Rx.Symbol.rxSubscriber]()).toBe(sub); + expect(sub[Rx.Symbol.rxSubscriber]()).to.equal(sub); }); describe('when created through create()', () => { it('should not call error() if next() handler throws an error', () => { - const errorSpy = jasmine.createSpy('error'); - const completeSpy = jasmine.createSpy('complete'); + const errorSpy = sinon.spy(); + const completeSpy = sinon.spy(); const subscriber = Subscriber.create( (value: any) => { @@ -26,10 +29,10 @@ describe('Subscriber', () => { subscriber.next(1); expect(() => { subscriber.next(2); - }).toThrow('error!'); + }).to.throw('error!'); - expect(errorSpy).not.toHaveBeenCalled(); - expect(completeSpy).not.toHaveBeenCalled(); + expect(errorSpy).not.have.been.called; + expect(completeSpy).not.have.been.called; }); }); @@ -45,7 +48,7 @@ describe('Subscriber', () => { sub.unsubscribe(); sub.next(); - expect(times).toBe(2); + expect(times).to.equal(2); }); it('should ignore error messages after unsubscription', () => { @@ -63,8 +66,8 @@ describe('Subscriber', () => { sub.next(); sub.error(); - expect(times).toBe(2); - expect(errorCalled).toBe(false); + expect(times).to.equal(2); + expect(errorCalled).to.be.false; }); it('should ignore complete messages after unsubscription', () => { @@ -82,7 +85,7 @@ describe('Subscriber', () => { sub.next(); sub.complete(); - expect(times).toBe(2); - expect(completeCalled).toBe(false); + expect(times).to.equal(2); + expect(completeCalled).to.be.false; }); }); diff --git a/spec/Subscription-spec.ts b/spec/Subscription-spec.ts index 89a3a2db1f..9862b105ea 100644 --- a/spec/Subscription-spec.ts +++ b/spec/Subscription-spec.ts @@ -1,12 +1,12 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; -import {DoneSignature} from './helpers/test-helper'; const Observable = Rx.Observable; const Subscription = Rx.Subscription; /** @test {Subscription} */ describe('Subscription', () => { - it('should not leak', (done: DoneSignature) => { + it('should not leak', (done: MochaDone) => { const tearDowns = []; const source1 = Observable.create((observer: Rx.Observer) => { @@ -33,13 +33,13 @@ describe('Subscription', () => { setTimeout(() => { expect(() => { subscription.unsubscribe(); - }).toThrow(new Rx.UnsubscriptionError([new Error('oops, I am a bad unsubscribe!')])); - expect(tearDowns).toEqual([1, 2, 3]); + }).to.throw(Rx.UnsubscriptionError); + expect(tearDowns).to.deep.equal([1, 2, 3]); done(); }); }); - it('should not leak when adding a bad custom subscription to a subscription', (done: DoneSignature) => { + it('should not leak when adding a bad custom subscription to a subscription', (done: MochaDone) => { const tearDowns = []; const sub = new Subscription(); @@ -55,7 +55,7 @@ describe('Subscription', () => { tearDowns.push(2); sub.add(({ unsubscribe: () => { - expect(sub.isUnsubscribed).toBe(true); + expect(sub.isUnsubscribed).to.be.true; throw new Error('Who is your daddy, and what does he do?'); } })); @@ -73,8 +73,8 @@ describe('Subscription', () => { setTimeout(() => { expect(() => { sub.unsubscribe(); - }).toThrow(new Rx.UnsubscriptionError([new Error('Who is your daddy, and what does he do?')])); - expect(tearDowns).toEqual([1, 2, 3]); + }).to.throw(Rx.UnsubscriptionError); + expect(tearDowns).to.deep.equal([1, 2, 3]); done(); }); }); diff --git a/spec/observables/ErrorObservable-spec.ts b/spec/observables/ErrorObservable-spec.ts index 1cb8dfc3b5..1f5248fff2 100644 --- a/spec/observables/ErrorObservable-spec.ts +++ b/spec/observables/ErrorObservable-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {ErrorObservable} from '../../dist/cjs/observable/ErrorObservable'; declare const expectObservable: any; @@ -9,14 +10,14 @@ describe('ErrorObservable', () => { it('should create expose a error property', () => { const e = new ErrorObservable('error'); - expect(e.error).toBe('error'); + expect(e.error).to.equal('error'); }); it('should create ErrorObservable via static create function', () => { const e = new ErrorObservable('error'); const r = ErrorObservable.create('error'); - expect(e).toEqual(r); + expect(e).to.deep.equal(r); }); it('should accept scheduler', () => { diff --git a/spec/observables/IteratorObservable-spec.ts b/spec/observables/IteratorObservable-spec.ts index bd72793797..0073334022 100644 --- a/spec/observables/IteratorObservable-spec.ts +++ b/spec/observables/IteratorObservable-spec.ts @@ -1,52 +1,52 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {IteratorObservable} from '../../dist/cjs/observable/IteratorObservable'; -declare const {expectObservable}; -import {DoneSignature} from '../helpers/test-helper'; +declare const expectObservable; declare const rxTestScheduler: Rx.TestScheduler; describe('IteratorObservable', () => { it('should create an Observable via constructor', () => { const source = new IteratorObservable([]); - expect(source instanceof IteratorObservable).toBe(true); + expect(source instanceof IteratorObservable).to.be.true; }); it('should create IteratorObservable via static create function', () => { const s = new IteratorObservable([]); const r = IteratorObservable.create([]); - expect(s).toEqual(r); + expect(s).to.deep.equal(r); }); it('should not accept null (or truthy-equivalent to null) iterator', () => { expect(() => { IteratorObservable.create(null); - }).toThrowError('iterator cannot be null.'); + }).to.throw(Error, 'iterator cannot be null.'); expect(() => { IteratorObservable.create(void 0); - }).toThrowError('iterator cannot be null.'); + }).to.throw(Error, 'iterator cannot be null.'); }); it('should not accept boolean as iterator', () => { expect(() => { IteratorObservable.create(false); - }).toThrowError('Object is not iterable'); + }).to.throw(Error, 'Object is not iterable'); }); it('should not accept non-function project', () => { expect(() => { IteratorObservable.create([], 42); - }).toThrowError('When provided, `project` must be a function.'); + }).to.throw(Error, 'When provided, `project` must be a function.'); }); - it('should emit members of an array iterator', (done: DoneSignature) => { + it('should emit members of an array iterator', (done: MochaDone) => { const expected = [10, 20, 30, 40]; IteratorObservable.create([10, 20, 30, 40]) .subscribe( - (x: number) => { expect(x).toBe(expected.shift()); }, + (x: number) => { expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); @@ -84,7 +84,7 @@ describe('IteratorObservable', () => { }); it('should emit members of an array iterator on a particular scheduler, ' + - 'but is unsubscribed early', (done: DoneSignature) => { + 'but is unsubscribed early', (done: MochaDone) => { const expected = [10, 20, 30, 40]; const source = IteratorObservable.create( @@ -96,35 +96,35 @@ describe('IteratorObservable', () => { const subscriber = Rx.Subscriber.create( (x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); if (x === 30) { subscriber.unsubscribe(); done(); } }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); source.subscribe(subscriber); }); - it('should emit members of an array iterator, and project them', (done: DoneSignature) => { + it('should emit members of an array iterator, and project them', (done: MochaDone) => { const expected = [100, 400, 900, 1600]; IteratorObservable.create([10, 20, 30, 40], (x: number) => x * x) .subscribe( - (x: number) => { expect(x).toBe(expected.shift()); }, + (x: number) => { expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); }); - it('should emit members of an array iterator, and project but raise an error', (done: DoneSignature) => { + it('should emit members of an array iterator, and project but raise an error', (done: MochaDone) => { const expected = [100, 400]; function project(x) { if (x === 30) { @@ -136,59 +136,59 @@ describe('IteratorObservable', () => { IteratorObservable.create([10, 20, 30, 40], project) .subscribe( (x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (err: any) => { - expect(expected.length).toBe(0); - expect(err.message).toBe('boom'); + expect(expected.length).to.equal(0); + expect(err.message).to.equal('boom'); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); - it('should emit characters of a string iterator', (done: DoneSignature) => { + it('should emit characters of a string iterator', (done: MochaDone) => { const expected = ['f', 'o', 'o']; IteratorObservable.create('foo') .subscribe( - (x: number) => { expect(x).toBe(expected.shift()); }, + (x: number) => { expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); }); - it('should emit characters of a string iterator, and project them', (done: DoneSignature) => { + it('should emit characters of a string iterator, and project them', (done: MochaDone) => { const expected = ['F', 'O', 'O']; IteratorObservable.create('foo', (x: string) => x.toUpperCase()) .subscribe( - (x: string) => { expect(x).toBe(expected.shift()); }, + (x: string) => { expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); }); - it('should be possible to unsubscribe in the middle of the iteration', (done: DoneSignature) => { + it('should be possible to unsubscribe in the middle of the iteration', (done: MochaDone) => { const expected = [10, 20, 30]; const subscriber = Rx.Subscriber.create( (x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); if (x === 30) { subscriber.unsubscribe(); done(); } }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); } ); diff --git a/spec/observables/ScalarObservable-spec.ts b/spec/observables/ScalarObservable-spec.ts index df4ef748ba..87a4d5010d 100644 --- a/spec/observables/ScalarObservable-spec.ts +++ b/spec/observables/ScalarObservable-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {ScalarObservable} from '../../dist/cjs/observable/ScalarObservable'; @@ -6,14 +7,14 @@ declare const rxTestScheduler: Rx.TestScheduler; describe('ScalarObservable', () => { it('should create expose a value property', () => { const s = new ScalarObservable(1); - expect(s.value).toBe(1); + expect(s.value).to.equal(1); }); it('should create ScalarObservable via static create function', () => { const s = new ScalarObservable(1); const r = ScalarObservable.create(1); - expect(s).toEqual(r); + expect(s).to.deep.equal(r); }); it('should not schedule further if subscriber unsubscribed', () => { diff --git a/spec/observables/SubscribeOnObservable-spec.ts b/spec/observables/SubscribeOnObservable-spec.ts index 5e69048411..a13dc39427 100644 --- a/spec/observables/SubscribeOnObservable-spec.ts +++ b/spec/observables/SubscribeOnObservable-spec.ts @@ -1,7 +1,9 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {SubscribeOnObservable} from '../../dist/cjs/observable/SubscribeOnObservable'; -declare const {hot, expectObservable, expectSubscriptions}; +declare const {hot, expectObservable, expectSubscriptions}; declare const rxTestScheduler: Rx.TestScheduler; describe('SubscribeOnObservable', () => { @@ -17,18 +19,18 @@ describe('SubscribeOnObservable', () => { it('should specify default scheduler if incorrect scheduler specified', () => { const e1 = hot('--a--b--|'); - const obj: any = jasmine.createSpy('dummy'); + const obj: any = sinon.spy(); const scheduler = (new SubscribeOnObservable(e1, 0, obj)).scheduler; - expect(scheduler).toBe(Rx.Scheduler.asap); + expect(scheduler).to.deep.equal(Rx.Scheduler.asap); }); it('should create observable via staic create function', () => { const s = new SubscribeOnObservable(null, null, rxTestScheduler); const r = SubscribeOnObservable.create(null, null, rxTestScheduler); - expect(s).toEqual(r); + expect(s).to.deep.equal(r); }); it('should subscribe after specified delay', () => { diff --git a/spec/observables/bindCallback-spec.ts b/spec/observables/bindCallback-spec.ts index 6d763cce05..ea62094823 100644 --- a/spec/observables/bindCallback-spec.ts +++ b/spec/observables/bindCallback-spec.ts @@ -1,5 +1,6 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -21,7 +22,7 @@ describe('Observable.bindCallback', () => { results.push('done'); }); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should emit one value chosen by a selector', () => { @@ -38,7 +39,7 @@ describe('Observable.bindCallback', () => { results.push('done'); }); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should emit an error when the selector throws', () => { @@ -57,13 +58,13 @@ describe('Observable.bindCallback', () => { throw 'should not complete'; }); - expect(results).toEqual([new Error('Yikes!')]); + expect(results).to.deep.equal([new Error('Yikes!')]); }); - it('should not emit, throw or complete if immediately unsubscribed', (done: DoneSignature) => { - const nextSpy = jasmine.createSpy('next'); - const throwSpy = jasmine.createSpy('throw'); - const completeSpy = jasmine.createSpy('complete'); + it('should not emit, throw or complete if immediately unsubscribed', (done: MochaDone) => { + const nextSpy = sinon.spy(); + const throwSpy = sinon.spy(); + const completeSpy = sinon.spy(); let timeout; function callback(datum, cb) { // Need to cb async in order for the unsub to trigger @@ -76,9 +77,9 @@ describe('Observable.bindCallback', () => { subscription.unsubscribe(); setTimeout(() => { - expect(nextSpy).not.toHaveBeenCalled(); - expect(throwSpy).not.toHaveBeenCalled(); - expect(completeSpy).not.toHaveBeenCalled(); + expect(nextSpy).not.have.been.called; + expect(throwSpy).not.have.been.called; + expect(completeSpy).not.have.been.called; clearTimeout(timeout); done(); @@ -103,7 +104,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should error if callback throws', () => { @@ -124,7 +125,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([new Error('haha no callback for you')]); + expect(results).to.deep.equal([new Error('haha no callback for you')]); }); it('should error if selector throws', () => { @@ -148,7 +149,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([new Error('what? a selector? I don\'t think so')]); + expect(results).to.deep.equal([new Error('what? a selector? I don\'t think so')]); }); it('should use a selector', () => { @@ -170,7 +171,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual(['42!!!', 'done']); + expect(results).to.deep.equal(['42!!!', 'done']); }); }); @@ -190,7 +191,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([[42, 1, 2, 3], 'done']); + expect(results).to.deep.equal([[42, 1, 2, 3], 'done']); }); it('should pass multiple inner arguments to the selector if there is one', () => { @@ -198,7 +199,7 @@ describe('Observable.bindCallback', () => { cb(datum, 1, 2, 3); } function selector(a, b, c, d) { - expect([a, b, c, d]).toEqual([42, 1, 2, 3]); + expect([a, b, c, d]).to.deep.equal([42, 1, 2, 3]); return a + b + c + d; } const boundCallback = Observable.bindCallback(callback, selector, rxTestScheduler); @@ -213,7 +214,7 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([48, 'done']); + expect(results).to.deep.equal([48, 'done']); }); it('should cache value for next subscription and not call callbackFunc again', () => { @@ -242,9 +243,9 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(calls).toBe(1); - expect(results1).toEqual([42, 'done']); - expect(results2).toEqual([42, 'done']); + expect(calls).to.equal(1); + expect(results1).to.deep.equal([42, 'done']); + expect(results2).to.deep.equal([42, 'done']); }); it('should not even call the callbackFn if immediately unsubscribed', () => { @@ -268,6 +269,6 @@ describe('Observable.bindCallback', () => { rxTestScheduler.flush(); - expect(calls).toBe(0); + expect(calls).to.equal(0); }); }); \ No newline at end of file diff --git a/spec/observables/bindNodeCallback-spec.ts b/spec/observables/bindNodeCallback-spec.ts index 0b15281fc9..117cafa264 100644 --- a/spec/observables/bindNodeCallback-spec.ts +++ b/spec/observables/bindNodeCallback-spec.ts @@ -1,5 +1,6 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -21,7 +22,7 @@ describe('Observable.bindNodeCallback', () => { results.push('done'); }); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should emit one value chosen by a selector', () => { @@ -38,7 +39,7 @@ describe('Observable.bindNodeCallback', () => { results.push('done'); }); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should raise error from callback', () => { @@ -60,7 +61,7 @@ describe('Observable.bindNodeCallback', () => { throw 'should not complete'; }); - expect(results).toEqual([error]); + expect(results).to.deep.equal([error]); }); it('should emit an error when the selector throws', () => { @@ -79,13 +80,13 @@ describe('Observable.bindNodeCallback', () => { throw 'should not complete'; }); - expect(results).toEqual([new Error('Yikes!')]); + expect(results).to.deep.equal([new Error('Yikes!')]); }); - it('should not emit, throw or complete if immediately unsubscribed', (done: DoneSignature) => { - const nextSpy = jasmine.createSpy('next'); - const throwSpy = jasmine.createSpy('throw'); - const completeSpy = jasmine.createSpy('complete'); + it('should not emit, throw or complete if immediately unsubscribed', (done: MochaDone) => { + const nextSpy = sinon.spy(); + const throwSpy = sinon.spy(); + const completeSpy = sinon.spy(); let timeout; function callback(datum, cb) { // Need to cb async in order for the unsub to trigger @@ -98,9 +99,9 @@ describe('Observable.bindNodeCallback', () => { subscription.unsubscribe(); setTimeout(() => { - expect(nextSpy).not.toHaveBeenCalled(); - expect(throwSpy).not.toHaveBeenCalled(); - expect(completeSpy).not.toHaveBeenCalled(); + expect(nextSpy).not.have.been.called; + expect(throwSpy).not.have.been.called; + expect(completeSpy).not.have.been.called; clearTimeout(timeout); done(); @@ -125,7 +126,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([42, 'done']); + expect(results).to.deep.equal([42, 'done']); }); it('should error if callback throws', () => { @@ -146,7 +147,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([new Error('haha no callback for you')]); + expect(results).to.deep.equal([new Error('haha no callback for you')]); }); it('should raise error from callback', () => { @@ -170,7 +171,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([error]); + expect(results).to.deep.equal([error]); }); it('should error if selector throws', () => { @@ -194,7 +195,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([new Error('what? a selector? I don\'t think so')]); + expect(results).to.deep.equal([new Error('what? a selector? I don\'t think so')]); }); it('should use a selector', () => { @@ -216,7 +217,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual(['42!!!', 'done']); + expect(results).to.deep.equal(['42!!!', 'done']); }); }); @@ -236,7 +237,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([[42, 1, 2, 3], 'done']); + expect(results).to.deep.equal([[42, 1, 2, 3], 'done']); }); it('should pass multiple inner arguments to the selector if there is one', () => { @@ -244,7 +245,7 @@ describe('Observable.bindNodeCallback', () => { cb(null, datum, 1, 2, 3); } function selector(a, b, c, d) { - expect([a, b, c, d]).toEqual([42, 1, 2, 3]); + expect([a, b, c, d]).to.deep.equal([42, 1, 2, 3]); return a + b + c + d; } const boundCallback = Observable.bindNodeCallback(callback, selector, rxTestScheduler); @@ -259,7 +260,7 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(results).toEqual([48, 'done']); + expect(results).to.deep.equal([48, 'done']); }); it('should cache value for next subscription and not call callbackFunc again', () => { @@ -288,8 +289,8 @@ describe('Observable.bindNodeCallback', () => { rxTestScheduler.flush(); - expect(calls).toBe(1); - expect(results1).toEqual([42, 'done']); - expect(results2).toEqual([42, 'done']); + expect(calls).to.equal(1); + expect(results1).to.deep.equal([42, 'done']); + expect(results2).to.deep.equal([42, 'done']); }); }); \ No newline at end of file diff --git a/spec/observables/combineLatest-spec.ts b/spec/observables/combineLatest-spec.ts index 6eb2fd51c9..74742990e3 100644 --- a/spec/observables/combineLatest-spec.ts +++ b/spec/observables/combineLatest-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -18,18 +18,18 @@ describe('Observable.combineLatest', () => { expectObservable(combined).toBe(expected, {u: 'ad', v: 'ae', w: 'af', x: 'bf', y: 'bg', z: 'cg'}); }); - it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: DoneSignature) => { + it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; //type definition need to be updated Observable.combineLatest(a, b, queueScheduler).subscribe((vals: any) => { - (expect(vals)).toDeepEqual(r.shift()); + expect(vals).to.deep.equal(r.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(r.length).toBe(0); + expect(r.length).to.equal(0); done(); }); }); diff --git a/spec/observables/concat-spec.ts b/spec/observables/concat-spec.ts index e9e22117f9..2ff78f5997 100644 --- a/spec/observables/concat-spec.ts +++ b/spec/observables/concat-spec.ts @@ -1,7 +1,6 @@ -/* globals describe, it, expect, expectObservable, expectSubscriptions, cold */ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -334,13 +333,13 @@ describe('Observable.concat', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should concat an immediately-scheduled source with an immediately-scheduled second', (done: DoneSignature) => { + it('should concat an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 3, 4, 5, 6, 7, 8]; Observable.concat(a, b, queueScheduler).subscribe((vals: number) => { - expect(vals).toBe(r.shift()); + expect(vals).to.equal(r.shift()); }, null, done); }); }); \ No newline at end of file diff --git a/spec/observables/defer-spec.ts b/spec/observables/defer-spec.ts index d8e4dc9346..fa642e59b8 100644 --- a/spec/observables/defer-spec.ts +++ b/spec/observables/defer-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; -declare const {hot, expectObservable, expectSubscriptions, type}; +declare const {hot, expectObservable, expectSubscriptions}; const Observable = Rx.Observable; @@ -28,33 +28,33 @@ describe('Observable.defer', () => { expectSubscriptions(source.subscriptions).toBe(sourceSubs); }); - it('should accept factory returns promise resolves', (done: DoneSignature) => { + it('should accept factory returns promise resolves', (done: MochaDone) => { const expected = 42; const e1 = Observable.defer(() => { return new Promise((resolve: any) => { resolve(expected); }); }); e1.subscribe((x: number) => { - expect(x).toBe(expected); + expect(x).to.equal(expected); done(); }, x => { - done.fail(); + done(new Error('should not be called')); }); }); - it('should accept factory returns promise rejects', (done: DoneSignature) => { + it('should accept factory returns promise rejects', (done: MochaDone) => { const expected = 42; const e1 = Observable.defer(() => { return new Promise((resolve: any, reject: any) => { reject(expected); }); }); e1.subscribe((x: number) => { - done.fail(); + done(new Error('should not be called')); }, x => { - expect(x).toBe(expected); + expect(x).to.equal(expected); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); diff --git a/spec/observables/dom/ajax-spec.ts b/spec/observables/dom/ajax-spec.ts index 207b81a101..8ec7575f14 100644 --- a/spec/observables/dom/ajax-spec.ts +++ b/spec/observables/dom/ajax-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../../dist/cjs/Rx.DOM'; import {root} from '../../../dist/cjs/util/root'; import {MockXMLHttpRequest} from '../../helpers/ajax-helper'; @@ -38,8 +39,8 @@ describe('Observable.ajax', () => { const request = MockXMLHttpRequest.mostRecent; - expect(request.url).toBe('/talk-to-me-goose'); - expect(request.requestHeaders).toEqual({ + expect(request.url).to.equal('/talk-to-me-goose'); + expect(request.requestHeaders).to.deep.equal({ 'Content-Type': 'kenny/loggins', 'Fly-Into-The': 'Dangah Zone!', 'Take-A-Ride-Into-The': 'Danger ZoooOoone!', @@ -65,7 +66,7 @@ describe('Observable.ajax', () => { complete = true; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 200, @@ -73,8 +74,8 @@ describe('Observable.ajax', () => { 'responseText': expected }); - expect(result).toBe(expected); - expect(complete).toBe(true); + expect(result).to.equal(expected); + expect(complete).to.be.true; }); it('should have error when resultSelector errors', () => { @@ -98,7 +99,7 @@ describe('Observable.ajax', () => { throw 'should not complete'; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 200, @@ -106,7 +107,7 @@ describe('Observable.ajax', () => { 'responseText': expected }); - expect(error).toEqual(new Error('ha! ha! fooled you!')); + expect(error).to.be.an('error', 'ha! ha! fooled you!'); }); it('should error if createXHR throws', () => { @@ -128,7 +129,7 @@ describe('Observable.ajax', () => { throw 'should not complete'; }); - expect(error).toEqual(new Error('wokka wokka')); + expect(error).to.be.an('error', 'wokka wokka'); }); it('should succeed on 200', () => { @@ -148,7 +149,7 @@ describe('Observable.ajax', () => { complete = true; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 200, @@ -156,9 +157,9 @@ describe('Observable.ajax', () => { 'responseText': JSON.stringify(expected) }); - expect(result.xhr).toBeDefined(); - expect(result.response).toBe(JSON.stringify({ foo: 'bar' })); - expect(complete).toBe(true); + expect(result.xhr).exist; + expect(result.response).to.deep.equal(JSON.stringify({ foo: 'bar' })); + expect(complete).to.be.true; }); it('should fail on 404', () => { @@ -181,7 +182,7 @@ describe('Observable.ajax', () => { throw 'should not complete'; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 404, @@ -189,9 +190,9 @@ describe('Observable.ajax', () => { 'responseText': 'Wee! I am text!' }); - expect(error instanceof Rx.AjaxError).toBe(true); - expect(error.message).toBe('ajax error 404'); - expect(error.status).toBe(404); + expect(error instanceof Rx.AjaxError).to.be.true; + expect(error.message).to.equal('ajax error 404'); + expect(error.status).to.equal(404); }); it('should fail on 404', () => { @@ -213,7 +214,7 @@ describe('Observable.ajax', () => { throw 'should not complete'; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 300, @@ -221,9 +222,9 @@ describe('Observable.ajax', () => { 'responseText': 'Wee! I am text!' }); - expect(error instanceof Rx.AjaxError).toBe(true); - expect(error.message).toBe('ajax error 300'); - expect(error.status).toBe(300); + expect(error instanceof Rx.AjaxError).to.be.true; + expect(error.message).to.equal('ajax error 300'); + expect(error.status).to.equal(300); }); it('should succeed no settings', () => { @@ -231,14 +232,14 @@ describe('Observable.ajax', () => { Rx.Observable.ajax('/flibbertyJibbet') .subscribe((x: any) => { - expect(x.status).toBe(200); - expect(x.xhr.method).toBe('GET'); - expect(x.xhr.responseText).toBe(expected); + expect(x.status).to.equal(200); + expect(x.xhr.method).to.equal('GET'); + expect(x.xhr.responseText).to.equal(expected); }, () => { throw 'should not have been called'; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 200, 'contentType': 'text/plain', @@ -253,14 +254,14 @@ describe('Observable.ajax', () => { .subscribe(() => { throw 'should not have been called'; }, (x: any) => { - expect(x.status).toBe(500); - expect(x.xhr.method).toBe('GET'); - expect(x.xhr.responseText).toBe(expected); + expect(x.status).to.equal(500); + expect(x.xhr.method).to.equal('GET'); + expect(x.xhr.responseText).to.equal(expected); }, () => { throw 'should not have been called'; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 500, 'contentType': 'text/plain', @@ -289,8 +290,8 @@ describe('Observable.ajax', () => { Rx.Observable.ajax(obj).subscribe(); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); - expect(MockXMLHttpRequest.mostRecent.data).toBe('foobar'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.data).to.equal('foobar'); }); it('can take FormData body', () => { @@ -303,8 +304,8 @@ describe('Observable.ajax', () => { Rx.Observable.ajax(obj).subscribe(); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); - expect(MockXMLHttpRequest.mostRecent.data).toBe(body); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.data).to.deep.equal(body); }); it('should not fail when FormData is undefined', () => { @@ -321,7 +322,7 @@ describe('Observable.ajax', () => { Rx.Observable.ajax(obj).subscribe(); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); }); it('should send by form-urlencoded format', () => { @@ -339,8 +340,8 @@ describe('Observable.ajax', () => { Rx.Observable.ajax(obj).subscribe(); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); - expect(MockXMLHttpRequest.mostRecent.data).toBe('%F0%9F%8C%9F=%F0%9F%9A%80'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.data).to.equal('%F0%9F%8C%9F=%F0%9F%9A%80'); }); it('should send by JSON', () => { @@ -358,8 +359,8 @@ describe('Observable.ajax', () => { Rx.Observable.ajax(obj).subscribe(); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); - expect(MockXMLHttpRequest.mostRecent.data).toBe('{"🌟":"🚀"}'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.data).to.equal('{"🌟":"🚀"}'); }); }); @@ -379,7 +380,7 @@ describe('Observable.ajax', () => { const request = MockXMLHttpRequest.mostRecent; - expect(request.url).toBe('/flibbertyJibbet'); + expect(request.url).to.equal('/flibbertyJibbet'); request.respondWith({ 'status': 200, @@ -387,8 +388,8 @@ describe('Observable.ajax', () => { 'responseText': JSON.stringify(expected) }); - expect(result).toEqual(expected); - expect(complete).toBe(true); + expect(result).to.deep.equal(expected); + expect(complete).to.be.true; }); it('should succeed on 200 with a resultSelector', () => { @@ -408,7 +409,7 @@ describe('Observable.ajax', () => { complete = true; }); - expect(MockXMLHttpRequest.mostRecent.url).toBe('/flibbertyJibbet'); + expect(MockXMLHttpRequest.mostRecent.url).to.equal('/flibbertyJibbet'); MockXMLHttpRequest.mostRecent.respondWith({ 'status': 200, @@ -416,10 +417,10 @@ describe('Observable.ajax', () => { 'responseText': JSON.stringify(expected) }); - expect(innerResult.xhr).toBeDefined(); - expect(innerResult.response).toEqual({ larf: 'hahahahaha' }); - expect(result).toBe('HAHAHAHAHA'); - expect(complete).toBe(true); + expect(innerResult.xhr).exist; + expect(innerResult.response).to.deep.equal({ larf: 'hahahahaha' }); + expect(result).to.equal('HAHAHAHAHA'); + expect(complete).to.be.true; }); }); @@ -439,9 +440,9 @@ describe('Observable.ajax', () => { const request = MockXMLHttpRequest.mostRecent; - expect(request.method).toBe('POST'); - expect(request.url).toBe('/flibbertyJibbet'); - expect(request.requestHeaders).toEqual({ + expect(request.method).to.equal('POST'); + expect(request.url).to.equal('/flibbertyJibbet'); + expect(request.requestHeaders).to.deep.equal({ 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }); @@ -452,9 +453,9 @@ describe('Observable.ajax', () => { 'responseText': JSON.stringify(expected) }); - expect(request.data).toEqual('foo=bar&hi=there%20you'); - expect(result.response).toEqual(expected); - expect(complete).toBe(true); + expect(request.data).to.equal('foo=bar&hi=there%20you'); + expect(result.response).to.deep.equal(expected); + expect(complete).to.be.true; }); }); }); diff --git a/spec/observables/dom/webSocket-spec.ts b/spec/observables/dom/webSocket-spec.ts index f38b085f90..a415920c16 100644 --- a/spec/observables/dom/webSocket-spec.ts +++ b/spec/observables/dom/webSocket-spec.ts @@ -1,3 +1,5 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../../dist/cjs/Rx.DOM'; import {MockWebSocket} from '../../helpers/ajax-helper'; @@ -34,18 +36,18 @@ describe('Observable.webSocket', () => { subject.next('ping'); subject.subscribe((x: string) => { - expect(x).toBe('pong'); + expect(x).to.equal('pong'); messageReceived = true; }); const socket = MockWebSocket.lastSocket; - expect(socket.url).toBe('ws://mysocket'); + expect(socket.url).to.equal('ws://mysocket'); socket.open(); - expect(socket.lastMessageSent).toBe('ping'); + expect(socket.lastMessageSent).to.equal('ping'); socket.triggerMessage(JSON.stringify('pong')); - expect(messageReceived).toBe(true); + expect(messageReceived).to.be.true; subject.unsubscribe(); }); @@ -67,7 +69,7 @@ describe('Observable.webSocket', () => { socket.triggerMessage(JSON.stringify(x)); }); - expect(results).toEqual(expected); + expect(results).to.deep.equal(expected); subject.unsubscribe(); }); @@ -81,15 +83,15 @@ describe('Observable.webSocket', () => { }); let socket = MockWebSocket.lastSocket; - expect(socket).not.toBeDefined(); + expect(socket).not.exist; subject.subscribe(); socket = MockWebSocket.lastSocket; - expect(socket.sent.length).toBe(0); + expect(socket.sent.length).to.equal(0); socket.open(); - expect(socket.sent.length).toBe(expected.length); + expect(socket.sent.length).to.equal(expected.length); subject.unsubscribe(); }); @@ -101,9 +103,9 @@ describe('Observable.webSocket', () => { socket.open(); subject.next('avast!'); - expect(socket.lastMessageSent).toBe('avast!'); + expect(socket.lastMessageSent).to.equal('avast!'); subject.next('ye swab!'); - expect(socket.lastMessageSent).toBe('ye swab!'); + expect(socket.lastMessageSent).to.equal('ye swab!'); subject.unsubscribe(); }); @@ -114,16 +116,18 @@ describe('Observable.webSocket', () => { const socket = MockWebSocket.lastSocket; socket.open(); - expect(socket.readyState).toBe(1); // open + expect(socket.readyState).to.equal(1); // open - spyOn(socket, 'close').and.callThrough(); - expect(socket.close).not.toHaveBeenCalled(); + sinon.spy(socket, 'close'); + + expect(socket.close).not.have.been.called; subject.complete(); - expect(socket.close).toHaveBeenCalled(); - expect(socket.readyState).toBe(3); // closed + expect(socket.close).have.been.called; + expect(socket.readyState).to.equal(3); // closed subject.unsubscribe(); + (socket.close).restore(); }); it('should close the socket with a code and a reason when errored', () => { @@ -132,13 +136,14 @@ describe('Observable.webSocket', () => { const socket = MockWebSocket.lastSocket; socket.open(); - spyOn(socket, 'close').and.callThrough(); - expect(socket.close).not.toHaveBeenCalled(); + sinon.spy(socket, 'close'); + expect(socket.close).not.have.been.called; subject.error({ code: 1337, reason: 'Too bad, so sad :('}); - expect(socket.close).toHaveBeenCalledWith(1337, 'Too bad, so sad :('); + expect(socket.close).have.been.calledWith(1337, 'Too bad, so sad :('); subject.unsubscribe(); + (socket.close).restore(); }); it('should allow resubscription after closure via complete', () => { @@ -153,8 +158,8 @@ describe('Observable.webSocket', () => { const socket2 = MockWebSocket.lastSocket; socket2.open(); - expect(socket2).not.toBe(socket1); - expect(socket2.lastMessageSent).toBe('a mariner yer not. yarrr.'); + expect(socket2).not.to.equal(socket1); + expect(socket2.lastMessageSent).to.equal('a mariner yer not. yarrr.'); subject.unsubscribe(); }); @@ -171,8 +176,8 @@ describe('Observable.webSocket', () => { const socket2 = MockWebSocket.lastSocket; socket2.open(); - expect(socket2).not.toBe(socket1); - expect(socket2.lastMessageSent).toBe('yo-ho! yo-ho!'); + expect(socket2).not.to.equal(socket1); + expect(socket2.lastMessageSent).to.equal('yo-ho! yo-ho!'); subject.unsubscribe(); }); @@ -190,7 +195,7 @@ describe('Observable.webSocket', () => { socket.open(); socket.triggerMessage(JSON.stringify(expected)); - expect(result).toEqual(expected); + expect(result).to.deep.equal(expected); subject.unsubscribe(); }); @@ -203,18 +208,18 @@ describe('Observable.webSocket', () => { subject.next('ping'); subject.subscribe((x: string) => { - expect(x).toBe('pong'); + expect(x).to.equal('pong'); messageReceived = true; }); const socket = MockWebSocket.lastSocket; - expect(socket.url).toBe('ws://mysocket'); + expect(socket.url).to.equal('ws://mysocket'); socket.open(); - expect(socket.lastMessageSent).toBe('ping'); + expect(socket.lastMessageSent).to.equal('ping'); socket.triggerMessage(JSON.stringify('pong')); - expect(messageReceived).toBe(true); + expect(messageReceived).to.be.true; subject.unsubscribe(); }); @@ -228,7 +233,7 @@ describe('Observable.webSocket', () => { subject.subscribe(); const socket = MockWebSocket.lastSocket; - expect(socket.protocol).toBe('someprotocol'); + expect(socket.protocol).to.equal('someprotocol'); subject.unsubscribe(); }); @@ -253,7 +258,7 @@ describe('Observable.webSocket', () => { socket.triggerMessage(x); }); - expect(results).toEqual(['ahoy!', 'yarr!', 'shove off!']); + expect(results).to.deep.equal(['ahoy!', 'yarr!', 'shove off!']); subject.unsubscribe(); }); @@ -267,9 +272,9 @@ describe('Observable.webSocket', () => { }); subject.subscribe((x: any) => { - expect(x).toBe('this should not happen'); + expect(x).to.equal('this should not happen'); }, (err: any) => { - expect(err).toEqual(new Error('I am a bad error')); + expect(err).to.be.an('error', 'I am a bad error'); }); const socket = MockWebSocket.lastSocket; @@ -286,7 +291,7 @@ describe('Observable.webSocket', () => { closingObserver: { next: function (x) { calls++; - expect(x).toBe(undefined); + expect(x).to.be.an('undefined'); } } }); @@ -295,17 +300,17 @@ describe('Observable.webSocket', () => { let socket = MockWebSocket.lastSocket; socket.open(); - expect(calls).toBe(0); + expect(calls).to.equal(0); subject.complete(); - expect(calls).toBe(1); + expect(calls).to.equal(1); subject.subscribe(); socket = MockWebSocket.lastSocket; socket.open(); subject.error({ code: 1337 }); - expect(calls).toBe(2); + expect(calls).to.equal(2); subject.unsubscribe(); }); @@ -326,23 +331,23 @@ describe('Observable.webSocket', () => { let socket = MockWebSocket.lastSocket; socket.open(); - expect(closes.length).toBe(0); + expect(closes.length).to.equal(0); socket.triggerClose(expected[0]); - expect(closes.length).toBe(1); + expect(closes.length).to.equal(1); subject.subscribe(null, function (err) { - expect(err).toBe(expected[1]); + expect(err).to.equal(expected[1]); }); socket = MockWebSocket.lastSocket; socket.open(); socket.triggerClose(expected[1]); - expect(closes.length).toBe(2); + expect(closes.length).to.equal(2); - expect(closes[0]).toBe(expected[0]); - expect(closes[1]).toBe(expected[1]); + expect(closes[0]).to.equal(expected[0]); + expect(closes[1]).to.equal(expected[1]); subject.unsubscribe(); }); @@ -366,7 +371,7 @@ describe('Observable.webSocket', () => { const socket = MockWebSocket.lastSocket; socket.open(); - expect(socket.lastMessageSent).toEqual({ sub: 'foo' }); + expect(socket.lastMessageSent).to.deep.equal({ sub: 'foo' }); [1, 2, 3, 4, 5].map((x: number) => { return { @@ -377,13 +382,14 @@ describe('Observable.webSocket', () => { socket.triggerMessage(JSON.stringify(x)); }); - expect(results).toEqual([1, 2, 4, 5]); + expect(results).to.deep.equal([1, 2, 4, 5]); - spyOn(socket, 'close').and.callThrough(); + sinon.spy(socket, 'close'); sub.unsubscribe(); - expect(socket.lastMessageSent).toEqual({ unsub: 'foo' }); + expect(socket.lastMessageSent).to.deep.equal({ unsub: 'foo' }); - expect(socket.close).toHaveBeenCalled(); + expect(socket.close).have.been.called; + (socket.close).restore(); }); }); }); \ No newline at end of file diff --git a/spec/observables/forkJoin-spec.ts b/spec/observables/forkJoin-spec.ts index eb24a28f35..cbf1fedc8c 100644 --- a/spec/observables/forkJoin-spec.ts +++ b/spec/observables/forkJoin-spec.ts @@ -1,6 +1,7 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -declare const {hot, expectObservable}; -import {DoneSignature, lowerCaseO} from '../helpers/test-helper'; +declare const {hot, expectObservable, expectSubscriptions}; +import {lowerCaseO} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -113,17 +114,17 @@ describe('Observable.forkJoin', () => { expectObservable(e1).toBe(expected); }); - it('should accept promise', (done: DoneSignature) => { + it('should accept promise', (done: MochaDone) => { const e1 = Observable.forkJoin( Observable.of(1), Promise.resolve(2) ); e1.subscribe((x: Array) => { - expect(x).toEqual([1, 2]); + expect(x).to.deep.equal([1, 2]); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/observables/from-promise-spec.ts b/spec/observables/from-promise-spec.ts index 3017cec84c..dcbe7d459d 100644 --- a/spec/observables/from-promise-spec.ts +++ b/spec/observables/from-promise-spec.ts @@ -1,172 +1,173 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; declare const process: any; const Observable = Rx.Observable; /** @test {fromPromise} */ describe('Observable.fromPromise', () => { - it('should emit one value from a resolved promise', (done: DoneSignature) => { + it('should emit one value from a resolved promise', (done: MochaDone) => { const promise = Promise.resolve(42); Observable.fromPromise(promise) .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should raise error from a rejected promise', (done: DoneSignature) => { + it('should raise error from a rejected promise', (done: MochaDone) => { const promise = Promise.reject('bad'); Observable.fromPromise(promise) .subscribe((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (e: any) => { - expect(e).toBe('bad'); + expect(e).to.equal('bad'); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); - it('should share the underlying promise with multiple subscribers', (done: DoneSignature) => { + it('should share the underlying promise with multiple subscribers', (done: MochaDone) => { const promise = Promise.resolve(42); const observable = Observable.fromPromise(promise); observable .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, null); setTimeout(() => { observable .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); }); - it('should accept already-resolved Promise', (done: DoneSignature) => { + it('should accept already-resolved Promise', (done: MochaDone) => { const promise = Promise.resolve(42); promise.then((x: number) => { - expect(x).toBe(42); + expect(x).to.equal(42); Observable.fromPromise(promise) .subscribe( - (y: number) => { expect(y).toBe(42); }, + (y: number) => { expect(y).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); - it('should emit a value from a resolved promise on a separate scheduler', (done: DoneSignature) => { + it('should emit a value from a resolved promise on a separate scheduler', (done: MochaDone) => { const promise = Promise.resolve(42); Observable.fromPromise(promise, Rx.Scheduler.asap) .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should raise error from a rejected promise on a separate scheduler', (done: DoneSignature) => { + it('should raise error from a rejected promise on a separate scheduler', (done: MochaDone) => { const promise = Promise.reject('bad'); Observable.fromPromise(promise, Rx.Scheduler.asap) .subscribe( - (x: any) => { done.fail('should not be called'); }, + (x: any) => { done(new Error('should not be called')); }, (e: any) => { - expect(e).toBe('bad'); + expect(e).to.equal('bad'); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); - it('should share the underlying promise with multiple subscribers on a separate scheduler', (done: DoneSignature) => { + it('should share the underlying promise with multiple subscribers on a separate scheduler', (done: MochaDone) => { const promise = Promise.resolve(42); const observable = Observable.fromPromise(promise, Rx.Scheduler.asap); observable .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, null); setTimeout(() => { observable .subscribe( - (x: number) => { expect(x).toBe(42); }, + (x: number) => { expect(x).to.equal(42); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); }); - it('should not emit, throw or complete if immediately unsubscribed', (done: DoneSignature) => { - const nextSpy = jasmine.createSpy('next'); - const throwSpy = jasmine.createSpy('throw'); - const completeSpy = jasmine.createSpy('complete'); + it('should not emit, throw or complete if immediately unsubscribed', (done: MochaDone) => { + const nextSpy = sinon.spy(); + const throwSpy = sinon.spy(); + const completeSpy = sinon.spy(); const promise = Promise.resolve(42); const subscription = Observable.fromPromise(promise) .subscribe(nextSpy, throwSpy, completeSpy); subscription.unsubscribe(); setTimeout(() => { - expect(nextSpy).not.toHaveBeenCalled(); - expect(throwSpy).not.toHaveBeenCalled(); - expect(completeSpy).not.toHaveBeenCalled(); + expect(nextSpy).not.have.been.called; + expect(throwSpy).not.have.been.called; + expect(completeSpy).not.have.been.called; done(); }); }); if (typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]') { - it('should globally throw unhandled errors on process', (done: DoneSignature) => { - let invoked = false; - process.on('uncaughtException', function (reason, p) { - if (invoked) { - return; - } - invoked = true; - expect(reason).toBe('fail'); - done(); - }); + it('should globally throw unhandled errors on process', (done: MochaDone) => { + const originalException = process.listeners('uncaughtException').pop(); + process.removeListener('uncaughtException', originalException); - Observable.fromPromise(Promise.reject('bad')) - .subscribe( - (x: any) => { done.fail('should not be called'); }, - (e: any) => { - expect(e).toBe('bad'); - throw 'fail'; - }, () => { - done.fail('should not be called'); - }); + process.once('uncaughtException', function (error) { + expect(error).to.be.an('error', 'fail'); + process.listeners('uncaughtException').push(originalException); + + done(); + }); + + Observable.fromPromise(Promise.reject('bad')) + .subscribe( + (x: any) => { done(new Error('should not be called')); }, + (e: any) => { + expect(e).to.equal('bad'); + throw new Error('fail'); + }, () => { + done(new Error('should not be called')); + }); }); } else if (typeof window === 'object' && Object.prototype.toString.call(window) === '[object global]') { - it('should globally throw unhandled errors on window', (done: DoneSignature) => { + it('should globally throw unhandled errors on window', (done: MochaDone) => { let invoked = false; function onException(e) { if (invoked) { return; } invoked = true; - expect(e).toBe('Uncaught fail'); + expect(e).to.equal('Uncaught fail'); done(); } @@ -174,12 +175,12 @@ describe('Observable.fromPromise', () => { Observable.fromPromise(Promise.reject('bad')) .subscribe( - (x: any) => { done.fail('should not be called'); }, + (x: any) => { done(new Error('should not be called')); }, (e: any) => { - expect(e).toBe('bad'); + expect(e).to.equal('bad'); throw 'fail'; }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); } diff --git a/spec/observables/from-spec.ts b/spec/observables/from-spec.ts index 3b606cf9de..31604878da 100644 --- a/spec/observables/from-spec.ts +++ b/spec/observables/from-spec.ts @@ -1,28 +1,31 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -declare const expectObservable: any; -import {DoneSignature} from '../helpers/test-helper'; import {$$iterator} from '../../dist/cjs/symbol/iterator'; -declare const Symbol: any; +declare const {expectObservable, Symbol}; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; /** @test {from} */ describe('Observable.from', () => { - it('should enumerate an Array', (done: DoneSignature) => { + it('should enumerate an Array', function (done: MochaDone) { + this.timeout(300); + const expected = [1, 2, 3]; let i = 0; Observable.from(expected).subscribe((x: number) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); - }, 300); + }); + + it('should handle an ArrayLike', function (done: MochaDone) { + this.timeout(300); - it('should handle an ArrayLike', (done: DoneSignature) => { const arrayLike = { length: 3, 0: 1, @@ -32,31 +35,35 @@ describe('Observable.from', () => { const expected = [1, 2, 3]; Observable.from(arrayLike).subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); - }, 300); + }); + + it('should handle an ArrayLike from arguments', function (done: MochaDone) { + this.timeout(300); - it('should handle an ArrayLike from arguments', (done: DoneSignature) => { function makeArrayLike(...args) { const expected = [1, 2, 3]; Observable.from(arguments).subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); } makeArrayLike(1, 2, 3); - }, 300); + }); + + it('should handle an ArrayLike with a mapFn', function (done: MochaDone) { + this.timeout(300); - it('should handle an ArrayLike with a mapFn', (done: DoneSignature) => { const arrayLike = { length: 3, 0: 1, @@ -67,15 +74,15 @@ describe('Observable.from', () => { const mapFn = (v, k) => v - k; Observable.from(arrayLike, mapFn).subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); - }, 300); + }); - it('should handle an ArrayLike with a thisArg', (done: DoneSignature) => { + it('should handle an ArrayLike with a thisArg', (done: MochaDone) => { const arrayLike = { length: 3, 0: 1, @@ -88,27 +95,27 @@ describe('Observable.from', () => { }; Observable.from(arrayLike, mapFn, {thing: 123}).subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should handle a promise', (done: DoneSignature) => { + it('should handle a promise', (done: MochaDone) => { const promise = Promise.resolve('pinky swear'); Observable.from(promise).subscribe((x: string) => { - expect(x).toBe('pinky swear'); + expect(x).to.equal('pinky swear'); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should handle an "observableque" object', (done: DoneSignature) => { + it('should handle an "observableque" object', (done: MochaDone) => { const observablesque = {}; observablesque[Symbol.observable] = () => { @@ -121,9 +128,9 @@ describe('Observable.from', () => { }; Observable.from(observablesque).subscribe((x: string) => { - expect(x).toBe('test'); + expect(x).to.equal('test'); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -147,18 +154,18 @@ describe('Observable.from', () => { expectObservable(e1).toBe(expected); }); - it('should handle a string', (done: DoneSignature) => { + it('should handle a string', (done: MochaDone) => { const expected = ['a', 'b', 'c']; Observable.from('abc').subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should handle any iterable thing', (done: DoneSignature) => { + it('should handle any iterable thing', (done: MochaDone) => { const iterable = {}; const iteratorResults = [ { value: 'one', done: false }, @@ -167,7 +174,7 @@ describe('Observable.from', () => { ]; const expected = ['one', 'two']; - expect($$iterator).toBe(Symbol.iterator); + expect($$iterator).to.equal(Symbol.iterator); iterable[Symbol.iterator] = () => { return { @@ -178,9 +185,9 @@ describe('Observable.from', () => { }; Observable.from(iterable).subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -191,16 +198,16 @@ describe('Observable.from', () => { Observable.from({}).subscribe(); }; - expect(r).toThrow(); + expect(r).to.throw(); }); - it('should handle object has observable symbol', (done: DoneSignature) => { + it('should handle object has observable symbol', (done: MochaDone) => { const value = 'x'; Observable.from(Observable.of(value)).subscribe((x: string) => { - expect(x).toBe(value); + expect(x).to.equal(value); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/observables/fromEvent-spec.ts b/spec/observables/fromEvent-spec.ts index dd718b8004..a64ac9127a 100644 --- a/spec/observables/fromEvent-spec.ts +++ b/spec/observables/fromEvent-spec.ts @@ -1,5 +1,5 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -29,10 +29,10 @@ describe('Observable.fromEvent', () => { subscription.unsubscribe(); - expect(onEventName).toBe('click'); - expect(typeof onHandler).toBe('function'); - expect(offEventName).toBe(onEventName); - expect(offHandler).toBe(onHandler); + expect(onEventName).to.equal('click'); + expect(typeof onHandler).to.equal('function'); + expect(offEventName).to.equal(onEventName); + expect(offHandler).to.equal(onHandler); }); it('should setup an event observable on objects with "addEventListener" and "removeEventListener" ', () => { @@ -59,10 +59,10 @@ describe('Observable.fromEvent', () => { subscription.unsubscribe(); - expect(onEventName).toBe('click'); - expect(typeof onHandler).toBe('function'); - expect(offEventName).toBe(onEventName); - expect(offHandler).toBe(onHandler); + expect(onEventName).to.equal('click'); + expect(typeof onHandler).to.equal('function'); + expect(offEventName).to.equal(onEventName); + expect(offHandler).to.equal(onHandler); }); it('should setup an event observable on objects with "addListener" and "removeListener" ', () => { @@ -89,13 +89,13 @@ describe('Observable.fromEvent', () => { subscription.unsubscribe(); - expect(onEventName).toBe('click'); - expect(typeof onHandler).toBe('function'); - expect(offEventName).toBe(onEventName); - expect(offHandler).toBe(onHandler); + expect(onEventName).to.equal('click'); + expect(typeof onHandler).to.equal('function'); + expect(offEventName).to.equal(onEventName); + expect(offHandler).to.equal(onHandler); }); - it('should pass through events that occur', (done: DoneSignature) => { + it('should pass through events that occur', (done: MochaDone) => { let send; const obj = { on: (name: string, handler: Function) => { @@ -108,9 +108,9 @@ describe('Observable.fromEvent', () => { Observable.fromEvent(obj, 'click').take(1) .subscribe((e: any) => { - expect(e).toBe('test'); + expect(e).to.equal('test'); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -118,7 +118,7 @@ describe('Observable.fromEvent', () => { send('test'); }); - it('should pass through events that occur and use the selector if provided', (done: DoneSignature) => { + it('should pass through events that occur and use the selector if provided', (done: MochaDone) => { let send; const obj = { on: (name: string, handler: Function) => { @@ -135,9 +135,9 @@ describe('Observable.fromEvent', () => { Observable.fromEvent(obj, 'click', selector).take(1) .subscribe((e: any) => { - expect(e).toBe('test!'); + expect(e).to.equal('test!'); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -145,7 +145,7 @@ describe('Observable.fromEvent', () => { send('test'); }); - it('should not fail if no event arguments are passed and the selector does not return', (done: DoneSignature) => { + it('should not fail if no event arguments are passed and the selector does not return', (done: MochaDone) => { let send; const obj = { on: (name: string, handler: Function) => { @@ -162,9 +162,9 @@ describe('Observable.fromEvent', () => { Observable.fromEvent(obj, 'click', selector).take(1) .subscribe((e: any) => { - expect(e).toBeUndefined(); + expect(e).not.exist; }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -172,7 +172,7 @@ describe('Observable.fromEvent', () => { send(); }); - it('should return a value from the selector if no event arguments are passed', (done: DoneSignature) => { + it('should return a value from the selector if no event arguments are passed', (done: MochaDone) => { let send; const obj = { on: (name: string, handler: Function) => { @@ -189,9 +189,9 @@ describe('Observable.fromEvent', () => { Observable.fromEvent(obj, 'click', selector).take(1) .subscribe((e: any) => { - expect(e).toBe('no arguments'); + expect(e).to.equal('no arguments'); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -199,7 +199,7 @@ describe('Observable.fromEvent', () => { send(); }); - it('should pass multiple arguments to selector from event emitter', (done: DoneSignature) => { + it('should pass multiple arguments to selector from event emitter', (done: MochaDone) => { let send; const obj = { on: (name: string, handler: Function) => { @@ -216,9 +216,9 @@ describe('Observable.fromEvent', () => { Observable.fromEvent(obj, 'click', selector).take(1) .subscribe((e: any) => { - expect(e).toEqual([1, 2, 3]); + expect(e).to.deep.equal([1, 2, 3]); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/observables/fromEventPattern-spec.ts b/spec/observables/fromEventPattern-spec.ts index 3197216bc1..8c5c3c9131 100644 --- a/spec/observables/fromEventPattern-spec.ts +++ b/spec/observables/fromEventPattern-spec.ts @@ -1,6 +1,5 @@ -/* globals describe, it, expect, jasmine */ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -21,7 +20,7 @@ describe('Observable.fromEventPattern', () => { //noop }); - expect(typeof addHandlerCalledWith).toBe('function'); + expect(addHandlerCalledWith).to.be.a('function'); }); it('should call removeHandler on unsubscription', () => { @@ -40,7 +39,7 @@ describe('Observable.fromEventPattern', () => { subscription.unsubscribe(); - expect(typeof removeHandlerCalledWith).toBe('function'); + expect(removeHandlerCalledWith).to.be.a('function'); }); it('should send errors in addHandler down the error path', () => { @@ -51,11 +50,11 @@ describe('Observable.fromEventPattern', () => { }).subscribe(() => { //noop }, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); }); }); - it('should accept a selector that maps outgoing values', (done: DoneSignature) => { + it('should accept a selector that maps outgoing values', (done: MochaDone) => { let target; const trigger = function (...args) { if (target) { @@ -75,9 +74,9 @@ describe('Observable.fromEventPattern', () => { Observable.fromEventPattern(addHandler, removeHandler, selector).take(1) .subscribe((x: any) => { - expect(x).toBe('testme!'); + expect(x).to.equal('testme!'); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -85,7 +84,7 @@ describe('Observable.fromEventPattern', () => { trigger('test', 'me'); }); - it('should send errors in the selector down the error path', (done: DoneSignature) => { + it('should send errors in the selector down the error path', (done: MochaDone) => { let target; const trigger = (value: any) => { if (target) { @@ -105,12 +104,12 @@ describe('Observable.fromEventPattern', () => { Observable.fromEventPattern(addHandler, removeHandler, selector) .subscribe((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); trigger('test'); diff --git a/spec/observables/if-spec.ts b/spec/observables/if-spec.ts index aa9a392f31..c694272d9d 100644 --- a/spec/observables/if-spec.ts +++ b/spec/observables/if-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {expectObservable} from '../helpers/marble-testing'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -27,71 +27,70 @@ describe('Observable.if', () => { }); it('should raise error when conditional throws', () => { - const e1 = Observable.if(() => { + const e1 = Observable.if((() => { throw 'error'; - }, Observable.of('a')); + }), Observable.of('a')); const expected = '#'; expectObservable(e1).toBe(expected); }); - it('should accept resolved promise as thenSource', (done: DoneSignature) => { + it('should accept resolved promise as thenSource', (done: MochaDone) => { const expected = 42; const e1 = Observable.if(() => true, new Promise((resolve: any) => { resolve(expected); })); e1.subscribe(x => { - expect(x).toBe(expected); + expect(x).to.equal(expected); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should accept resolved promise as elseSource', (done: DoneSignature) => { + it('should accept resolved promise as elseSource', (done: MochaDone) => { const expected = 42; const e1 = Observable.if(() => false, Observable.of('a'), new Promise((resolve: any) => { resolve(expected); })); e1.subscribe(x => { - expect(x).toBe(expected); - done(); + expect(x).to.equal(expected); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should accept rejected promise as elseSource', (done: DoneSignature) => { + it('should accept rejected promise as elseSource', (done: MochaDone) => { const expected = 42; const e1 = Observable.if(() => false, Observable.of('a'), new Promise((resolve: any, reject: any) => { reject(expected); })); e1.subscribe(x => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - expect(x).toBe(expected); + expect(x).to.equal(expected); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); - it('should accept rejected promise as thenSource', (done: DoneSignature) => { + it('should accept rejected promise as thenSource', (done: MochaDone) => { const expected = 42; const e1 = Observable.if(() => true, new Promise((resolve: any, reject: any) => { reject(expected); })); e1.subscribe(x => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - expect(x).toBe(expected); + expect(x).to.equal(expected); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); }); diff --git a/spec/observables/interval-spec.ts b/spec/observables/interval-spec.ts index d9c2503112..ac5bf04561 100644 --- a/spec/observables/interval-spec.ts +++ b/spec/observables/interval-spec.ts @@ -1,8 +1,8 @@ -/* globals describe, it, expect, spyOn */ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -declare const {expectObservable}; -import {DoneSignature} from '../helpers/test-helper'; +declare const expectObservable; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -14,9 +14,9 @@ describe('Observable.interval', () => { }); it('should specify default scheduler if incorrect scheduler specified', () => { - const scheduler = (Observable.interval(10, jasmine.createSpy('dummy'))).scheduler; + const scheduler = (Observable.interval(10, sinon.stub())).scheduler; - expect(scheduler).toBe(Rx.Scheduler.async); + expect(scheduler).to.equal(Rx.Scheduler.async); }); it('should emit when relative interval set to zero', () => { @@ -33,7 +33,7 @@ describe('Observable.interval', () => { expectObservable(e1).toBe(expected, [0, 1, 2, 3, 4, 5, 6]); }); - it('should emit values until unsubscribed', (done: DoneSignature) => { + it('should emit values until unsubscribed', (done: MochaDone) => { const values = []; const expected = [0, 1, 2, 3, 4, 5, 6]; const e1 = Observable.interval(5); @@ -41,13 +41,13 @@ describe('Observable.interval', () => { values.push(x); if (x === 6) { subscription.unsubscribe(); - expect(values).toEqual(expected); + expect(values).to.deep.equal(expected); done(); } }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); }); diff --git a/spec/observables/merge-spec.ts b/spec/observables/merge-spec.ts index 47de99aad1..671cee1e0b 100644 --- a/spec/observables/merge-spec.ts +++ b/spec/observables/merge-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, expectObservable, expectSubscriptions}; @@ -24,7 +25,7 @@ describe('Observable.merge(...observables)', () => { const e1 = Observable.of('a'); const result = Observable.merge(e1); - expect(e1).toBe(result); + expect(e1).to.equal(result); }); it('should merge hot and hot', () => { diff --git a/spec/observables/of-spec.ts b/spec/observables/of-spec.ts index 3b631f6d30..7753df67d5 100644 --- a/spec/observables/of-spec.ts +++ b/spec/observables/of-spec.ts @@ -1,25 +1,25 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {ArrayObservable} from '../../dist/cjs/observable/ArrayObservable'; import {ScalarObservable} from '../../dist/cjs/observable/ScalarObservable'; import {EmptyObservable} from '../../dist/cjs/observable/EmptyObservable'; -declare const {expectObservable}; -import {DoneSignature} from '../helpers/test-helper'; +declare const expectObservable; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; /** @test {of} */ describe('Observable.of', () => { - it('should create an observable from the provided values', (done: DoneSignature) => { + it('should create an observable from the provided values', (done: MochaDone) => { const x = { foo: 'bar' }; const expected = [1, 'a', x]; let i = 0; Observable.of(1, 'a', x) .subscribe((y: any) => { - expect(y).toBe(expected[i++]); + expect(y).to.equal(expected[i++]); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -27,37 +27,37 @@ describe('Observable.of', () => { it('should return a scalar observable if only passed one value', () => { const obs = Observable.of('one'); - expect(obs instanceof ScalarObservable).toBe(true); + expect(obs instanceof ScalarObservable).to.be.true; }); it('should return a scalar observable if only passed one value and a scheduler', () => { const obs = Observable.of('one', Rx.Scheduler.queue); - expect(obs instanceof ScalarObservable).toBe(true); + expect(obs instanceof ScalarObservable).to.be.true; }); it('should return an array observable if passed many values', () => { const obs = Observable.of('one', 'two', 'three'); - expect(obs instanceof ArrayObservable).toBe(true); + expect(obs instanceof ArrayObservable).to.be.true; }); it('should return an empty observable if passed no values', () => { const obs = Observable.of(); - expect(obs instanceof EmptyObservable).toBe(true); + expect(obs instanceof EmptyObservable).to.be.true; }); it('should return an empty observable if passed only a scheduler', () => { const obs = Observable.of(Rx.Scheduler.queue); - expect(obs instanceof EmptyObservable).toBe(true); + expect(obs instanceof EmptyObservable).to.be.true; }); - it('should emit one value', (done: DoneSignature) => { + it('should emit one value', (done: MochaDone) => { let calls = 0; Observable.of(42).subscribe((x: number) => { - expect(++calls).toBe(1); - expect(x).toBe(42); + expect(++calls).to.equal(1); + expect(x).to.equal(42); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -68,7 +68,7 @@ describe('Observable.of', () => { Observable.of('a', 'b', 'c', rxTestScheduler), rxTestScheduler ); - expect(source instanceof ScalarObservable).toBe(true); + expect(source instanceof ScalarObservable).to.be.true; const result = source.concatAll(); expectObservable(result).toBe('(abc|)'); }); @@ -79,7 +79,7 @@ describe('Observable.of', () => { Observable.of('d', 'e', 'f', rxTestScheduler), rxTestScheduler ); - expect(source instanceof ArrayObservable).toBe(true); + expect(source instanceof ArrayObservable).to.be.true; const result = source.concatAll(); expectObservable(result).toBe('(abcdef|)'); diff --git a/spec/observables/range-spec.ts b/spec/observables/range-spec.ts index 1e13610f82..7fb89ffea6 100644 --- a/spec/observables/range-spec.ts +++ b/spec/observables/range-spec.ts @@ -1,6 +1,7 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import * as Rx from '../../dist/cjs/Rx'; import {RangeObservable} from '../../dist/cjs/observable/RangeObservable'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const asap = Rx.Scheduler.asap; @@ -12,26 +13,28 @@ describe('Observable.range', () => { Observable.range(12, 4).subscribe(function (x) { results.push(x); }); - expect(results).toEqual([12, 13, 14, 15]); + expect(results).to.deep.equal([12, 13, 14, 15]); }); - it('should accept a scheduler', (done: DoneSignature) => { + it('should accept a scheduler', (done: MochaDone) => { const expected = [12, 13, 14, 15]; - spyOn(asap, 'schedule').and.callThrough(); + sinon.spy(asap, 'schedule'); const source = Observable.range(12, 4, asap); - expect((source).scheduler).toBe(asap); + expect((source).scheduler).to.deep.equal(asap); source.subscribe(function (x) { - expect(asap.schedule).toHaveBeenCalled(); + expect(asap.schedule).have.been.called; const exp = expected.shift(); - expect(x).toBe(exp); + expect(x).to.equal(exp); }, function (x) { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { + (asap.schedule).restore(); done(); }); + }); }); @@ -39,18 +42,20 @@ describe('RangeObservable', () => { describe('create', () => { it('should create a RangeObservable', () => { const observable = RangeObservable.create(12, 4); - expect(observable instanceof RangeObservable).toBe(true); + expect(observable instanceof RangeObservable).to.be.true; }); it('should accept a scheduler', () => { const observable = RangeObservable.create(12, 4, asap); - expect((observable).scheduler).toBe(asap); + expect((observable).scheduler).to.deep.equal(asap); }); }); describe('dispatch', () => { it('should complete if index >= end', () => { - const obj: Rx.Subscriber = jasmine.createSpyObj('subscriber', ['next', 'error', 'complete']); + const o = new Rx.Subscriber(); + const obj: Rx.Subscriber = sinon.stub(o); + const state = { subscriber: obj, index: 10, @@ -60,12 +65,14 @@ describe('RangeObservable', () => { RangeObservable.dispatch(state); - expect(state.subscriber.complete).toHaveBeenCalled(); - expect(state.subscriber.next).not.toHaveBeenCalled(); + expect(state.subscriber.complete).have.been.called; + expect(state.subscriber.next).not.have.been.called; }); it('should next out another value and increment the index and start', () => { - const obj: Rx.Subscriber = jasmine.createSpyObj('subscriber', ['next', 'error', 'complete']); + const o = new Rx.Subscriber(); + const obj: Rx.Subscriber = sinon.stub(o); + const state = { subscriber: obj, index: 1, @@ -74,16 +81,16 @@ describe('RangeObservable', () => { }; const thisArg = { - schedule: jasmine.createSpy('schedule') + schedule: sinon.spy() }; RangeObservable.dispatch.call(thisArg, state); - expect(state.subscriber.complete).not.toHaveBeenCalled(); - expect(state.subscriber.next).toHaveBeenCalledWith(5); - expect(state.start).toBe(6); - expect(state.index).toBe(2); - expect(thisArg.schedule).toHaveBeenCalledWith(state); + expect(state.subscriber.complete).not.have.been.called; + expect(state.subscriber.next).have.been.calledWith(5); + expect(state.start).to.equal(6); + expect(state.index).to.equal(2); + expect(thisArg.schedule).have.been.calledWith(state); }); }); }); \ No newline at end of file diff --git a/spec/observables/throw-spec.ts b/spec/observables/throw-spec.ts index d7a5d97d5e..49013bcfe6 100644 --- a/spec/observables/throw-spec.ts +++ b/spec/observables/throw-spec.ts @@ -1,17 +1,17 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; /** @test {throw} */ describe('Observable.throw', () => { - it('should emit one value', (done: DoneSignature) => { + it('should emit one value', (done: MochaDone) => { let calls = 0; Observable.throw('bad').subscribe(() => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (err: any) => { - expect(++calls).toBe(1); - expect(err).toBe('bad'); + expect(++calls).to.equal(1); + expect(err).to.equal('bad'); done(); }); }); diff --git a/spec/observables/timer-spec.ts b/spec/observables/timer-spec.ts index 3934d723c1..382a417b85 100644 --- a/spec/observables/timer-spec.ts +++ b/spec/observables/timer-spec.ts @@ -1,6 +1,6 @@ import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -declare const {time, expectObservable}; +declare const {time, expectObservable}; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; diff --git a/spec/observables/using-spec.ts b/spec/observables/using-spec.ts index cc4f0c04c4..063e92c12f 100644 --- a/spec/observables/using-spec.ts +++ b/spec/observables/using-spec.ts @@ -1,11 +1,11 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const Subscription = Rx.Subscription; describe('Observable.using', () => { - it('should dispose of the resource when the subscription is disposed', (done: DoneSignature) => { + it('should dispose of the resource when the subscription is disposed', (done) => { let disposed = false; const source = Observable.using( () => new Subscription(() => disposed = true), @@ -18,11 +18,11 @@ describe('Observable.using', () => { if (disposed) { done(); } else { - done.fail('disposed should be true but was false'); + done(new Error('disposed should be true but was false')); } }); - it('should accept factory returns promise resolves', (done: DoneSignature) => { + it('should accept factory returns promise resolves', (done: MochaDone) => { const expected = 42; let disposed = false; @@ -31,15 +31,15 @@ describe('Observable.using', () => { (resource) => new Promise((resolve: any) => { resolve(expected); })); e1.subscribe(x => { - expect(x).toBe(expected); + expect(x).to.equal(expected); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should accept factory returns promise rejects', (done: DoneSignature) => { + it('should accept factory returns promise rejects', (done: MochaDone) => { const expected = 42; let disposed = false; @@ -48,16 +48,16 @@ describe('Observable.using', () => { (resource) => new Promise((resolve: any, reject: any) => { reject(expected); })); e1.subscribe(x => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - expect(x).toBe(expected); + expect(x).to.equal(expected); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); - it('should raise error when resource factory throws', (done: DoneSignature) => { + it('should raise error when resource factory throws', (done: MochaDone) => { const expectedError = 'expected'; const error = 'error'; @@ -71,16 +71,16 @@ describe('Observable.using', () => { ); source.subscribe((x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - expect(x).toBe(expectedError); + expect(x).to.equal(expectedError); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); - it('should raise error when observable factory throws', (done: DoneSignature) => { + it('should raise error when observable factory throws', (done: MochaDone) => { const error = 'error'; let disposed = false; @@ -92,12 +92,12 @@ describe('Observable.using', () => { ); source.subscribe((x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - expect(x).toBe(error); + expect(x).to.equal(error); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); }); diff --git a/spec/observables/zip-spec.ts b/spec/observables/zip-spec.ts index 805ea1020e..a036c88dd3 100644 --- a/spec/observables/zip-spec.ts +++ b/spec/observables/zip-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const Symbol: any; @@ -22,7 +22,7 @@ describe('Observable.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should zip the provided observables', (done: DoneSignature) => { + it('should zip the provided observables', (done: MochaDone) => { const expected = ['a1', 'b2', 'c3']; let i = 0; @@ -30,7 +30,7 @@ describe('Observable.zip', () => { Observable.from(['a', 'b', 'c']), Observable.from([1, 2, 3]), (a: string, b: number) => a + b) .subscribe((x: string) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, null, done); }); @@ -119,7 +119,7 @@ describe('Observable.zip', () => { // since zip will call `next()` in advance, total calls when // zipped with 3 other values should be 4. - expect(nextCalled).toBe(4); + expect(nextCalled).to.equal(4); }); it('should work with never observable and empty iterable', () => { @@ -565,14 +565,14 @@ describe('Observable.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: DoneSignature) => { + it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 5], [3, 6]]; let i = 0; Observable.zip(a, b).subscribe((vals: Array) => { - (expect(vals)).toDeepEqual(r[i++]); + expect(vals).to.deep.equal(r[i++]); }, null, done); }); }); \ No newline at end of file diff --git a/spec/operators/audit-spec.ts b/spec/operators/audit-spec.ts index ee385786f5..ee2970b9e6 100644 --- a/spec/operators/audit-spec.ts +++ b/spec/operators/audit-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -284,7 +284,7 @@ describe('Observable.prototype.audit', () => { expectSubscriptions(e1.subscriptions).toBe(subs); }); - it('should audit by promise resolves', (done: DoneSignature) => { + it('should audit by promise resolves', (done: MochaDone) => { const e1 = Observable.interval(10).take(5); const expected = [0, 1, 2, 3]; @@ -292,18 +292,18 @@ describe('Observable.prototype.audit', () => { return new Promise((resolve: any) => { resolve(42); }); }).subscribe( (x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); }); - it('should raise error when promise rejects', (done: DoneSignature) => { + it('should raise error when promise rejects', (done: MochaDone) => { const e1 = Observable.interval(10).take(10); const expected = [0, 1, 2]; const error = new Error('error'); @@ -316,14 +316,14 @@ describe('Observable.prototype.audit', () => { } }).subscribe( (x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, (err: any) => { - expect(err).toBe(error); - expect(expected.length).toBe(0); + expect(err).to.be.an('error', 'error'); + expect(expected.length).to.equal(0); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); } ); }); diff --git a/spec/operators/auditTime-spec.ts b/spec/operators/auditTime-spec.ts index 1f919e2135..c5549cec1a 100644 --- a/spec/operators/auditTime-spec.ts +++ b/spec/operators/auditTime-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -18,11 +18,11 @@ describe('Observable.prototype.auditTime', () => { expectSubscriptions(e1.subscriptions).toBe(subs); }); - it('should auditTime events by 50 time units', (done: DoneSignature) => { + it('should auditTime events by 50 time units', (done: MochaDone) => { Observable.of(1, 2, 3) .auditTime(50) .subscribe((x: number) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, null, () => { done(); }); @@ -36,7 +36,7 @@ describe('Observable.prototype.auditTime', () => { ) .auditTime(50, rxTestScheduler) .subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }); rxTestScheduler.flush(); diff --git a/spec/operators/bufferToggle-spec.ts b/spec/operators/bufferToggle-spec.ts index d8cf165cc6..4a82000915 100644 --- a/spec/operators/bufferToggle-spec.ts +++ b/spec/operators/bufferToggle-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -38,7 +39,7 @@ describe('Observable.prototype.bufferToggle', () => { const innerVals = ['x', 'y', 'z']; expectObservable(e1.bufferToggle(e2, (x: string) => { - expect(x).toBe(innerVals.shift()); + expect(x).to.equal(innerVals.shift()); return e3; })).toBe(expected, values); }); diff --git a/spec/operators/bufferWhen-spec.ts b/spec/operators/bufferWhen-spec.ts index 4aad5df054..f55b72dee3 100644 --- a/spec/operators/bufferWhen-spec.ts +++ b/spec/operators/bufferWhen-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -297,7 +297,7 @@ describe('Observable.prototype.bufferWhen', () => { // closing Observables, because doing such would constantly recreate a new // buffer in a synchronous infinite loop until the stack overflows. This also // happens with buffer in RxJS 4. - it('should NOT handle hot inner empty', (done: DoneSignature) => { + it('should NOT handle hot inner empty', (done: MochaDone) => { const source = Observable.of(1, 2, 3, 4, 5, 6, 7, 8, 9); const closing = Observable.empty(); const TOO_MANY_INVOCATIONS = 30; @@ -306,10 +306,10 @@ describe('Observable.prototype.bufferWhen', () => { .bufferWhen(() => closing) .takeWhile((val: any, index: number) => index < TOO_MANY_INVOCATIONS) .subscribe((val: any) => { - expect(Array.isArray(val)).toBe(true); - expect(val.length).toBe(0); + expect(Array.isArray(val)).to.be.true; + expect(val.length).to.equal(0); }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/catch-spec.ts b/spec/operators/catch-spec.ts index 19fc89d2a9..3e8a92dea2 100644 --- a/spec/operators/catch-spec.ts +++ b/spec/operators/catch-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestSchdeuler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -213,16 +213,16 @@ describe('Observable.prototype.catch', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should pass the error as the first argument', (done: DoneSignature) => { + it('should pass the error as the first argument', (done: MochaDone) => { Observable.throw('bad') .catch((err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); return Observable.empty(); }) .subscribe(() => { //noop }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/combineAll-spec.ts b/spec/operators/combineAll-spec.ts index 4276e253bb..adad373139 100644 --- a/spec/operators/combineAll-spec.ts +++ b/spec/operators/combineAll-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -448,28 +448,28 @@ describe('Observable.prototype.combineAll', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should combine two observables', (done: DoneSignature) => { + it('should combine two observables', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const expected = [[3, 4], [3, 5], [3, 6], [3, 7], [3, 8]]; Observable.of(a, b).combineAll().subscribe((vals: any) => { - expect(vals).toEqual(expected.shift()); + expect(vals).to.deep.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should combine two immediately-scheduled observables', (done: DoneSignature) => { + it('should combine two immediately-scheduled observables', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 4], [2, 5], [3, 5], [3, 6], [3, 7], [3, 8]]; Observable.of>(a, b, queueScheduler).combineAll() .subscribe((vals: any) => { - (expect(vals)).toDeepEqual(r.shift()); + expect(vals).to.deep.equal(r.shift()); }, null, () => { - expect(r.length).toEqual(0); + expect(r.length).to.equal(0); done(); }); }); diff --git a/spec/operators/concat-spec.ts b/spec/operators/concat-spec.ts index 6feaa6d2ae..0c1b8fdc0a 100644 --- a/spec/operators/concat-spec.ts +++ b/spec/operators/concat-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -15,7 +15,7 @@ describe('Observable.prototype.concat', () => { expectObservable(e1.concat(e2, rxTestScheduler)).toBe(expected); }); - it('should work properly with scalar observables', (done: DoneSignature) => { + it('should work properly with scalar observables', (done: MochaDone) => { const results = []; const s1 = Observable @@ -30,10 +30,10 @@ describe('Observable.prototype.concat', () => { s1.subscribe((x: number) => { results.push('Next: ' + x); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { results.push('Completed'); - expect(results).toEqual(['Next: 1', 'Next: 2', 'Completed']); + expect(results).to.deep.equal(['Next: 1', 'Next: 2', 'Completed']); done(); } ); diff --git a/spec/operators/concatAll-spec.ts b/spec/operators/concatAll-spec.ts index 562161641a..53afecf30e 100644 --- a/spec/operators/concatAll-spec.ts +++ b/spec/operators/concatAll-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -19,7 +19,8 @@ describe('Observable.prototype.concatAll', () => { expectObservable(result).toBe(expected); }); - it('should concat sources from promise', (done: DoneSignature) => { + it('should concat sources from promise', function (done: MochaDone) { + this.timeout(2000); const sources = Rx.Observable.from([ new Promise((res: any) => { res(0); }), new Promise((res: any) => { res(1); }), @@ -30,14 +31,16 @@ describe('Observable.prototype.concatAll', () => { const res = []; (sources.concatAll()).subscribe( (x: number) => { res.push(x); }, - (err: any) => { done.fail('should not be called.'); }, + (err: any) => { done(new Error('should not be called')); }, () => { - expect(res).toEqual([0, 1, 2, 3]); + expect(res).to.deep.equal([0, 1, 2, 3]); done(); }); - }, 2000); + }); + + it('should concat and raise error from promise', function (done: MochaDone) { + this.timeout(2000); - it('should concat and raise error from promise', (done: DoneSignature) => { const sources = Rx.Observable.from([ new Promise((res: any) => { res(0); }), new Promise((res: any, rej: any) => { rej(1); }), @@ -49,12 +52,12 @@ describe('Observable.prototype.concatAll', () => { (sources.concatAll()).subscribe( (x: number) => { res.push(x); }, (err: any) => { - expect(res.length).toBe(1); - expect(err).toBe(1); + expect(res.length).to.equal(1); + expect(err).to.equal(1); done(); }, - () => { done.fail('should not be called.'); }); - }, 2000); + () => { done(new Error('should not be called')); }); + }); it('should concat all observables in an observable', () => { const e1 = Rx.Observable.from([ diff --git a/spec/operators/concatMap-spec.ts b/spec/operators/concatMap-spec.ts index 7f4a3f6f77..09851b3994 100644 --- a/spec/operators/concatMap-spec.ts +++ b/spec/operators/concatMap-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -637,7 +637,7 @@ describe('Observable.prototype.concatMap', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and concatenate', (done: DoneSignature) => { + it('should map values to constant resolved promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: any) => Observable.from(Promise.resolve(42)); @@ -646,29 +646,29 @@ describe('Observable.prototype.concatMap', () => { (x: any) => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([42, 42, 42, 42]); + expect(results).to.deep.equal([42, 42, 42, 42]); done(); }); }); - it('should map values to constant rejected promises and concatenate', (done: DoneSignature) => { + it('should map values to constant rejected promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: any) => Observable.from(Promise.reject(42)); source.concatMap(project).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.deep.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should map values to resolved promises and concatenate', (done: DoneSignature) => { + it('should map values to resolved promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.resolve(value + index)); @@ -677,29 +677,29 @@ describe('Observable.prototype.concatMap', () => { (x: any) => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([4, 4, 4, 4]); + expect(results).to.deep.equal([4, 4, 4, 4]); done(); }); }); - it('should map values to rejected promises and concatenate', (done: DoneSignature) => { + it('should map values to rejected promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.reject('' + value + '-' + index)); source.concatMap(project).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual('4-0'); + expect(err).to.deep.equal('4-0'); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should concatMap values to resolved promises with resultSelector', (done: DoneSignature) => { + it('should concatMap values to resolved promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const resultSelectorCalledWith = []; const project = (value: number, index: number) => Observable.from((Promise.resolve([value, index]))); @@ -720,15 +720,15 @@ describe('Observable.prototype.concatMap', () => { (x: any) => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([8, 8, 8, 8]); - (expect(resultSelectorCalledWith)).toDeepEqual(expectedCalls); + expect(results).to.deep.equal([8, 8, 8, 8]); + expect(resultSelectorCalledWith).to.deep.equal(expectedCalls); done(); }); }); - it('should concatMap values to rejected promises with resultSelector', (done: DoneSignature) => { + it('should concatMap values to rejected promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: number, index: number) => Observable.from(Promise.reject('' + value + '-' + index)); @@ -738,12 +738,12 @@ describe('Observable.prototype.concatMap', () => { source.concatMap(project, resultSelector).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual('4-0'); + expect(err).to.deep.equal('4-0'); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); }); \ No newline at end of file diff --git a/spec/operators/concatMapTo-spec.ts b/spec/operators/concatMapTo-spec.ts index 9c457129ad..2618bd5d11 100644 --- a/spec/operators/concatMapTo-spec.ts +++ b/spec/operators/concatMapTo-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -300,7 +300,7 @@ describe('Observable.prototype.concatMapTo', () => { expectObservable(result).toBe(expected); }); - it('should map values to constant resolved promises and concatenate', (done: DoneSignature) => { + it('should map values to constant resolved promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const results = []; @@ -309,31 +309,31 @@ describe('Observable.prototype.concatMapTo', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([42, 42, 42, 42]); + expect(results).to.deep.equal([42, 42, 42, 42]); done(); }); }); - it('should map values to constant rejected promises and concatenate', (done: DoneSignature) => { + it('should map values to constant rejected promises and concatenate', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); source.concatMapTo(Observable.from(Promise.reject(42))).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should concatMapTo values to resolved promises with resultSelector', (done: DoneSignature) => { + it('should concatMapTo values to resolved promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const resultSelectorCalledWith = []; const inner = Observable.from(Promise.resolve(42)); @@ -354,16 +354,16 @@ describe('Observable.prototype.concatMapTo', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([8, 8, 8, 8]); - (expect(resultSelectorCalledWith)).toDeepEqual(expectedCalls); + expect(results).to.deep.equal([8, 8, 8, 8]); + expect(resultSelectorCalledWith).to.deep.equal(expectedCalls); done(); }); }); - it('should concatMapTo values to rejected promises with resultSelector', (done: DoneSignature) => { + it('should concatMapTo values to rejected promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const inner = Observable.from(Promise.reject(42)); const resultSelector = () => { @@ -372,14 +372,14 @@ describe('Observable.prototype.concatMapTo', () => { source.concatMapTo(inner, resultSelector).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); }); \ No newline at end of file diff --git a/spec/operators/count-spec.ts b/spec/operators/count-spec.ts index da4dbb4162..d552af1db0 100644 --- a/spec/operators/count-spec.ts +++ b/spec/operators/count-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -69,34 +69,34 @@ describe('Observable.prototype.count', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should count a range() source observable', (done: DoneSignature) => { + it('should count a range() source observable', (done: MochaDone) => { Rx.Observable.range(1, 10).count().subscribe( (value: number) => { - expect(value).toEqual(10); + expect(value).to.equal(10); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should count a range().skip(1) source observable', (done: DoneSignature) => { + it('should count a range().skip(1) source observable', (done: MochaDone) => { Rx.Observable.range(1, 10).skip(1).count().subscribe( (value: number) => { - expect(value).toEqual(9); + expect(value).to.equal(9); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should count a range().take(1) source observable', (done: DoneSignature) => { + it('should count a range().take(1) source observable', (done: MochaDone) => { Rx.Observable.range(1, 10).take(1).count().subscribe( (value: number) => { - expect(value).toEqual(1); + expect(value).to.equal(1); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/debounce-spec.ts b/spec/operators/debounce-spec.ts index 2bd40dfb76..9a0e144d70 100644 --- a/spec/operators/debounce-spec.ts +++ b/spec/operators/debounce-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -348,7 +348,7 @@ describe('Observable.prototype.debounce', () => { } }); - it('should delay by promise resolves', (done: DoneSignature) => { + it('should delay by promise resolves', (done: MochaDone) => { const e1 = Observable.concat(Observable.of(1), Observable.timer(10).mapTo(2), Observable.timer(10).mapTo(3), @@ -359,17 +359,17 @@ describe('Observable.prototype.debounce', () => { e1.debounce(() => { return new Promise((resolve: any) => { resolve(42); }); }).subscribe((x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should raises error when promise rejects', (done: DoneSignature) => { + it('should raises error when promise rejects', (done: MochaDone) => { const e1 = Observable.concat(Observable.of(1), Observable.timer(10).mapTo(2), Observable.timer(10).mapTo(3), @@ -385,13 +385,13 @@ describe('Observable.prototype.debounce', () => { return new Promise((resolve: any) => { resolve(42); }); } }).subscribe((x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, (err: any) => { - expect(err).toBe(error); - expect(expected.length).toBe(0); + expect(err).to.be.an('error', 'error'); + expect(expected.length).to.equal(0); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); }); \ No newline at end of file diff --git a/spec/operators/do-spec.ts b/spec/operators/do-spec.ts index 2c9c245107..a4b67374e4 100644 --- a/spec/operators/do-spec.ts +++ b/spec/operators/do-spec.ts @@ -1,5 +1,5 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; const Observable = Rx.Observable; @@ -26,7 +26,7 @@ describe('Observable.prototype.do', () => { }) .subscribe(); - expect(value).toBe(42); + expect(value).to.equal(42); }); it('should complete with a callback', () => { @@ -35,13 +35,13 @@ describe('Observable.prototype.do', () => { err = x; }) .subscribe(null, function (ex) { - expect(ex).toBe('bad'); + expect(ex).to.equal('bad'); }); - expect(err).toBe('bad'); + expect(err).to.equal('bad'); }); - it('should handle everything with an observer', (done: DoneSignature) => { + it('should handle everything with an observer', (done: MochaDone) => { const expected = [1, 2, 3]; const results = []; @@ -51,16 +51,16 @@ describe('Observable.prototype.do', () => { results.push(x); }, error: (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, complete: () => { - expect(results).toEqual(expected); + expect(results).to.deep.equal(expected); done(); } }).subscribe(); }); - it('should handle everything with a Subject', (done: DoneSignature) => { + it('should handle everything with a Subject', (done: MochaDone) => { const expected = [1, 2, 3]; const results = []; const subject = new Subject(); @@ -70,10 +70,10 @@ describe('Observable.prototype.do', () => { results.push(x); }, error: (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, complete: () => { - expect(results).toEqual(expected); + expect(results).to.deep.equal(expected); done(); } }); @@ -86,27 +86,27 @@ describe('Observable.prototype.do', () => { it('should handle an error with a callback', () => { let errored = false; Observable.throw('bad').do(null, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); }) .subscribe(null, (err: any) => { errored = true; - expect(err).toBe('bad'); + expect(err).to.equal('bad'); }); - expect(errored).toBe(true); + expect(errored).to.be.true; }); it('should handle an error with observer', () => { let errored = false; Observable.throw('bad').do({ error: function (err) { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); } }) .subscribe(null, function (err) { errored = true; - expect(err).toBe('bad'); + expect(err).to.equal('bad'); }); - expect(errored).toBe(true); + expect(errored).to.be.true; }); it('should handle complete with observer', () => { @@ -118,7 +118,7 @@ describe('Observable.prototype.do', () => { } }).subscribe(); - expect(completed).toBe(true); + expect(completed).to.be.true; }); it('should handle next with observer', () => { @@ -130,7 +130,7 @@ describe('Observable.prototype.do', () => { } }).subscribe(); - expect(value).toBe('hi'); + expect(value).to.equal('hi'); }); it('should raise error if next handler raises error', () => { @@ -139,7 +139,7 @@ describe('Observable.prototype.do', () => { throw new Error('bad'); } }).subscribe(null, (err: any) => { - expect(err.message).toBe('bad'); + expect(err.message).to.equal('bad'); }); }); @@ -149,7 +149,7 @@ describe('Observable.prototype.do', () => { throw new Error('bad'); } }).subscribe(null, (err: any) => { - expect(err.message).toBe('bad'); + expect(err.message).to.equal('bad'); }); }); @@ -159,7 +159,7 @@ describe('Observable.prototype.do', () => { throw new Error('bad'); } }).subscribe(null, (err: any) => { - expect(err.message).toBe('bad'); + expect(err.message).to.equal('bad'); }); }); diff --git a/spec/operators/elementAt-spec.ts b/spec/operators/elementAt-spec.ts index da905a2210..40c529a82f 100644 --- a/spec/operators/elementAt-spec.ts +++ b/spec/operators/elementAt-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -97,7 +98,7 @@ describe('Observable.prototype.elementAt', () => { it('should throw if index is smaller than zero', () => { expect(() => { (Observable.range(0, 10)).elementAt(-1); }) - .toThrow(new Rx.ArgumentOutOfRangeError()); + .to.throw(Rx.ArgumentOutOfRangeError); }); it('should raise error if index is out of range but does not have default value', () => { diff --git a/spec/operators/every-spec.ts b/spec/operators/every-spec.ts index a7ebcf7bc6..9f7ab07469 100644 --- a/spec/operators/every-spec.ts +++ b/spec/operators/every-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -26,7 +27,7 @@ describe('Observable.prototype.every', () => { const thisArg = {}; Observable.of(1).every(function (value: number, index: number) { - expect(this).toBe(thisArg); + expect(this).to.deep.equal(thisArg); return true; }, thisArg).subscribe(); @@ -36,7 +37,7 @@ describe('Observable.prototype.every', () => { const thisArg = {}; Observable.of(1, 2, 3, 4).every(function (value: number, index: number) { - expect(this).toBe(thisArg); + expect(this).to.deep.equal(thisArg); return true; }, thisArg).subscribe(); }); @@ -49,7 +50,7 @@ describe('Observable.prototype.every', () => { observer.complete(); }) .every(function (value: number, index: number) { - expect(this).toBe(thisArg); + expect(this).to.deep.equal(thisArg); }, thisArg).subscribe(); }); diff --git a/spec/operators/exhaust-spec.ts b/spec/operators/exhaust-spec.ts index 5c5a9af8d7..534f7cdaf4 100644 --- a/spec/operators/exhaust-spec.ts +++ b/spec/operators/exhaust-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -187,29 +187,29 @@ describe('Observable.prototype.exhaust', () => { expectSubscriptions(x.subscriptions).toBe(xsubs); }); - it('should handle an observable of promises', (done: DoneSignature) => { + it('should handle an observable of promises', (done: MochaDone) => { const expected = [1]; (Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) .exhaust() .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should handle an observable of promises, where one rejects', (done: DoneSignature) => { + it('should handle an observable of promises, where one rejects', (done: MochaDone) => { (Observable.of(Promise.reject(2), Promise.resolve(1))) .exhaust() .subscribe((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (err: any) => { - expect(err).toBe(2); + expect(err).to.equal(2); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); }); diff --git a/spec/operators/expand-spec.ts b/spec/operators/expand-spec.ts index dde6ee4ca2..c550bc1a19 100644 --- a/spec/operators/expand-spec.ts +++ b/spec/operators/expand-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const Symbol: any; const Observable = Rx.Observable; @@ -295,7 +295,7 @@ describe('Observable.prototype.expand', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should recursively flatten promises', (done: DoneSignature) => { + it('should recursively flatten promises', (done: MochaDone) => { const expected = [1, 2, 4, 8, 16]; (Observable.of(1)) .expand((x: number): any => { @@ -305,14 +305,14 @@ describe('Observable.prototype.expand', () => { return Promise.resolve(x + x); }) .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should recursively flatten Arrays', (done: DoneSignature) => { + it('should recursively flatten Arrays', (done: MochaDone) => { const expected = [1, 2, 4, 8, 16]; (Observable).of(1) .expand((x: number): any => { @@ -322,14 +322,14 @@ describe('Observable.prototype.expand', () => { return [x + x]; }) .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should recursively flatten lowercase-o observables', (done: DoneSignature) => { + it('should recursively flatten lowercase-o observables', (done: MochaDone) => { const expected = [1, 2, 4, 8, 16]; const project = (x: any, index: number) => { if (x === 16) { @@ -352,9 +352,9 @@ describe('Observable.prototype.expand', () => { (Observable.of(1)) .expand(project) .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); diff --git a/spec/operators/filter-spec.ts b/spec/operators/filter-spec.ts index ace9753a56..a4b42121c7 100644 --- a/spec/operators/filter-spec.ts +++ b/spec/operators/filter-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -116,7 +116,7 @@ describe('Observable.prototype.filter', () => { const r = source .filter(predicate) .do(null, null, () => { - expect(invoked).toEqual(7); + expect(invoked).to.equal(7); }); expectObservable(r).toBe(expected); @@ -244,17 +244,17 @@ describe('Observable.prototype.filter', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should send errors down the error path', (done: DoneSignature) => { + it('should send errors down the error path', (done: MochaDone) => { Observable.of(42).filter(((x: number, index: number) => { throw 'bad'; })) .subscribe((x: number) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }); }); diff --git a/spec/operators/finally-spec.ts b/spec/operators/finally-spec.ts index c89ed0d1a8..7e644bcf28 100644 --- a/spec/operators/finally-spec.ts +++ b/spec/operators/finally-spec.ts @@ -1,15 +1,15 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; /** @test {finally} */ describe('Observable.prototype.finally', () => { - it('should call finally after complete', (done: DoneSignature) => { + it('should call finally after complete', (done: MochaDone) => { let completed = false; Observable.of(1, 2, 3) .finally(() => { - expect(completed).toBe(true); + expect(completed).to.be.true; done(); }) .subscribe(null, null, () => { @@ -17,7 +17,7 @@ describe('Observable.prototype.finally', () => { }); }); - it('should call finally after error', (done: DoneSignature) => { + it('should call finally after error', (done: MochaDone) => { let thrown = false; Observable.of(1, 2, 3) .map(function (x) { @@ -27,7 +27,7 @@ describe('Observable.prototype.finally', () => { return x; }) .finally(() => { - expect(thrown).toBe(true); + expect(thrown).to.be.true; done(); }) .subscribe(null, () => { @@ -35,12 +35,12 @@ describe('Observable.prototype.finally', () => { }); }); - it('should call finally upon disposal', (done: DoneSignature) => { + it('should call finally upon disposal', (done: MochaDone) => { let disposed = false; const subscription = Observable .timer(100) .finally(() => { - expect(disposed).toBe(true); + expect(disposed).to.be.true; done(); }).subscribe(); disposed = true; @@ -48,7 +48,7 @@ describe('Observable.prototype.finally', () => { }); it('should call finally when synchronously subscribing to and unsubscribing ' + - 'from a shared Observable', (done: DoneSignature) => { + 'from a shared Observable', (done: MochaDone) => { Observable.interval(50) .finally(done) .share() @@ -56,7 +56,7 @@ describe('Observable.prototype.finally', () => { .unsubscribe(); }); - it('should call two finally instances in succession on a shared Observable', (done: DoneSignature) => { + it('should call two finally instances in succession on a shared Observable', (done: MochaDone) => { let invoked = 0; function checkFinally() { invoked += 1; diff --git a/spec/operators/find-spec.ts b/spec/operators/find-spec.ts index 311981b110..d02c7799ca 100644 --- a/spec/operators/find-spec.ts +++ b/spec/operators/find-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -24,7 +25,7 @@ describe('Observable.prototype.find', () => { it('should throw if not provided a function', () => { expect(() => { (Observable.of('yut', 'yee', 'sam')).find('yee'); - }).toThrow(new TypeError('predicate is not a function')); + }).to.throw(TypeError, 'predicate is not a function'); }); it('should not emit if source does not emit', () => { diff --git a/spec/operators/first-spec.ts b/spec/operators/first-spec.ts index 27c7864968..b00dc591e3 100644 --- a/spec/operators/first-spec.ts +++ b/spec/operators/first-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, asDiagram, expectObservable, expectSubscriptions}; @@ -178,8 +179,8 @@ describe('Observable.prototype.first', () => { const sub = '^ !'; const predicate = function (x) { return x === 'c'; }; const resultSelector = function (x, i) { - expect(i).toBe(1); - expect(x).toBe('c'); + expect(i).to.equal(1); + expect(x).to.equal('c'); return 'x'; }; diff --git a/spec/operators/groupBy-spec.ts b/spec/operators/groupBy-spec.ts index 12bf0009ad..23047e82dc 100644 --- a/spec/operators/groupBy-spec.ts +++ b/spec/operators/groupBy-spec.ts @@ -1,7 +1,7 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; import {GroupedObservable} from '../../dist/cjs/operator/groupBy'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -34,7 +34,7 @@ describe('Observable.prototype.groupBy', () => { return out; } - it('should group values', (done: DoneSignature) => { + it('should group values', (done: MochaDone) => { const expectedGroups = [ { key: 1, values: [1, 3] }, { key: 0, values: [2] } @@ -44,15 +44,15 @@ describe('Observable.prototype.groupBy', () => { .groupBy((x: number) => x % 2) .subscribe((g: any) => { const expectedGroup = expectedGroups.shift(); - expect(g.key).toBe(expectedGroup.key); + expect(g.key).to.equal(expectedGroup.key); g.subscribe((x: any) => { - expect(x).toBe(expectedGroup.values.shift()); + expect(x).to.deep.equal(expectedGroup.values.shift()); }); }, null, done); }); - it('should group values with an element selector', (done: DoneSignature) => { + it('should group values with an element selector', (done: MochaDone) => { const expectedGroups = [ { key: 1, values: ['1!', '3!'] }, { key: 0, values: ['2!'] } @@ -62,15 +62,15 @@ describe('Observable.prototype.groupBy', () => { .groupBy((x: number) => x % 2, (x: number) => x + '!') .subscribe((g: any) => { const expectedGroup = expectedGroups.shift(); - expect(g.key).toBe(expectedGroup.key); + expect(g.key).to.equal(expectedGroup.key); g.subscribe((x: any) => { - expect(x).toBe(expectedGroup.values.shift()); + expect(x).to.deep.equal(expectedGroup.values.shift()); }); }, null, done); }); - it('should group values with a duration selector', (done: DoneSignature) => { + it('should group values with a duration selector', (done: MochaDone) => { const expectedGroups = [ { key: 1, values: [1, 3] }, { key: 0, values: [2, 4] }, @@ -85,10 +85,10 @@ describe('Observable.prototype.groupBy', () => { (g: any) => g.skip(1)) .subscribe((g: any) => { const expectedGroup = expectedGroups.shift(); - expect(g.key).toBe(expectedGroup.key); + expect(g.key).to.equal(expectedGroup.key); g.subscribe((x: any) => { - expect(x).toBe(expectedGroup.values.shift()); + expect(x).to.deep.equal(expectedGroup.values.shift()); }); }, null, done); }); @@ -188,8 +188,8 @@ describe('Observable.prototype.groupBy', () => { const source = e1 .groupBy((val: string) => val.toLowerCase().trim()) .do((group: any) => { - expect(group.key).toBe('foo'); - expect(group instanceof GroupedObservable).toBe(true); + expect(group.key).to.equal('foo'); + expect(group instanceof GroupedObservable).to.be.true; }) .map((group: any) => { return group.key; }); @@ -1345,7 +1345,7 @@ describe('Observable.prototype.groupBy', () => { expectSubscriptions(e1.subscriptions).toBe(expectedSubs); }); - it('should not break lift() composability', (done: DoneSignature) => { + it('should not break lift() composability', (done: MochaDone) => { class MyCustomObservable extends Rx.Observable { lift(operator: Rx.Operator): Rx.Observable { const observable = new MyCustomObservable(); @@ -1365,7 +1365,7 @@ describe('Observable.prototype.groupBy', () => { (x: string) => x + '!' ); - expect(result instanceof MyCustomObservable).toBe(true); + expect(result instanceof MyCustomObservable).to.be.true; const expectedGroups = [ { key: 1, values: ['1!', '3!'] }, @@ -1375,13 +1375,13 @@ describe('Observable.prototype.groupBy', () => { result .subscribe((g: any) => { const expectedGroup = expectedGroups.shift(); - expect(g.key).toBe(expectedGroup.key); + expect(g.key).to.equal(expectedGroup.key); g.subscribe((x: any) => { - expect(x).toBe(expectedGroup.values.shift()); + expect(x).to.deep.equal(expectedGroup.values.shift()); }); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/last-spec.ts b/spec/operators/last-spec.ts index e9f7f4532f..be5476d89f 100644 --- a/spec/operators/last-spec.ts +++ b/spec/operators/last-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -102,8 +103,8 @@ describe('Observable.prototype.last', () => { const predicate = function (x) { return x === 'c'; }; const resultSelector = function (x, i) { - expect(i).toBe(1); - expect(x).toBe('c'); + expect(i).to.equal(1); + expect(x).to.equal('c'); return 'x'; }; diff --git a/spec/operators/let-spec.ts b/spec/operators/let-spec.ts index d320dc1755..81f3342cef 100644 --- a/spec/operators/let-spec.ts +++ b/spec/operators/let-spec.ts @@ -1,9 +1,9 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; /** @test {let} */ describe('Observable.prototype.let', () => { - it('should be able to compose with let', (done: DoneSignature) => { + it('should be able to compose with let', (done: MochaDone) => { const expected = ['aa', 'bb']; let i = 0; @@ -13,9 +13,9 @@ describe('Observable.prototype.let', () => { .from(['a', 'b']) .let(foo) .subscribe(function (x) { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/map-spec.ts b/spec/operators/map-spec.ts index d6e0efc922..f56b5355c1 100644 --- a/spec/operators/map-spec.ts +++ b/spec/operators/map-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -35,7 +36,7 @@ describe('Observable.prototype.map', () => { it('should throw an error if not passed a function', () => { expect(() => { Observable.of(1, 2, 3).map('potato'); - }).toThrow(new TypeError('argument is not a function. Are you looking for `mapTo()`?')); + }).to.throw(TypeError, 'argument is not a function. Are you looking for `mapTo()`?'); }); it('should map multiple values', () => { @@ -89,7 +90,7 @@ describe('Observable.prototype.map', () => { .subscribe(throwError); }; - expect(r).toThrow(); + expect(r).to.throw(); }); it('should not map an empty observable', () => { @@ -101,7 +102,7 @@ describe('Observable.prototype.map', () => { const r = a .map((x: any) => { invoked++; return x; }) .do(null, null, () => { - expect(invoked).toBe(0); + expect(invoked).to.equal(0); }); expectObservable(r).toBe(expected); @@ -131,7 +132,7 @@ describe('Observable.prototype.map', () => { invoked++; return (parseInt(x) + 1) + (index * 10); }).do(null, null, () => { - expect(invoked).toBe(4); + expect(invoked).to.equal(4); }); expectObservable(r).toBe(expected, values); @@ -149,7 +150,7 @@ describe('Observable.prototype.map', () => { invoked++; return (parseInt(x) + 1) + (index * 10); }).do(null, null, () => { - expect(invoked).toBe(4); + expect(invoked).to.equal(4); }); expectObservable(r).toBe(expected, values); @@ -167,7 +168,7 @@ describe('Observable.prototype.map', () => { invoked++; return (parseInt(x) + 1) + (index * 10); }).do(null, null, () => { - expect(invoked).toBe(4); + expect(invoked).to.equal(4); }); expectObservable(r).toBe(expected, values, 'too bad'); @@ -185,11 +186,11 @@ describe('Observable.prototype.map', () => { const r = a .map(function (x: string, index: number) { invoked++; - expect(this).toEqual(foo); + expect(this).to.equal(foo); return (parseInt(x) + 1) + (index * 10); }, 42) .do(null, null, () => { - expect(invoked).toBe(4); + expect(invoked).to.equal(4); }); expectObservable(r).toBe(expected, values); @@ -208,8 +209,8 @@ describe('Observable.prototype.map', () => { .map((x: string) => { invoked1++; return parseInt(x) * 2; }) .map((x: number) => { invoked2++; return x / 2; }) .do(null, null, () => { - expect(invoked1).toBe(7); - expect(invoked2).toBe(7); + expect(invoked1).to.equal(7); + expect(invoked2).to.equal(7); }); expectObservable(r).toBe(expected, values); diff --git a/spec/operators/mapTo-spec.ts b/spec/operators/mapTo-spec.ts index 55e84ed6a6..ed2549e37a 100644 --- a/spec/operators/mapTo-spec.ts +++ b/spec/operators/mapTo-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -61,7 +62,7 @@ describe('Observable.prototype.mapTo', () => { .subscribe(throwError); }; - expect(r).toThrow(); + expect(r).to.throw(); }); it('should not map an empty observable', () => { diff --git a/spec/operators/max-spec.ts b/spec/operators/max-spec.ts index 47cd7a41d5..3aa008ab1e 100644 --- a/spec/operators/max-spec.ts +++ b/spec/operators/max-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -94,34 +94,34 @@ describe('Observable.prototype.max', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should max a range() source observable', (done: DoneSignature) => { + it('should max a range() source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10000)).max().subscribe( (value: number) => { - expect(value).toEqual(10000); + expect(value).to.equal(10000); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should max a range().skip(1) source observable', (done: DoneSignature) => { + it('should max a range().skip(1) source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10)).skip(1).max().subscribe( (value: number) => { - expect(value).toEqual(10); + expect(value).to.equal(10); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should max a range().take(1) source observable', (done: DoneSignature) => { + it('should max a range().take(1) source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10)).take(1).max().subscribe( (value: number) => { - expect(value).toEqual(1); + expect(value).to.equal(1); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/merge-spec.ts b/spec/operators/merge-spec.ts index 37970229e5..25d0d030c4 100644 --- a/spec/operators/merge-spec.ts +++ b/spec/operators/merge-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -22,29 +22,29 @@ describe('Observable.prototype.merge', () => { expectSubscriptions(e2.subscriptions).toBe(e2subs); }); - it('should merge a source with a second', (done: DoneSignature) => { + it('should merge a source with a second', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const r = [1, 2, 3, 4, 5, 6, 7, 8]; a.merge(b).subscribe((val: number) => { - expect(val).toBe(r.shift()); + expect(val).to.equal(r.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should merge an immediately-scheduled source with an immediately-scheduled second', (done: DoneSignature) => { + it('should merge an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 4, 3, 5, 6, 7, 8]; a.merge(b, queueScheduler).subscribe((val: number) => { - expect(val).toBe(r.shift()); + expect(val).to.equal(r.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -277,23 +277,23 @@ describe('Observable.prototype.merge', () => { }); describe('Observable.prototype.mergeAll', () => { - it('should merge two observables', (done: DoneSignature) => { + it('should merge two observables', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6, 7, 8); const r = [1, 2, 3, 4, 5, 6, 7, 8]; Observable.of(a, b).mergeAll().subscribe((val: number) => { - expect(val).toBe(r.shift()); + expect(val).to.equal(r.shift()); }, null, done); }); - it('should merge two immediately-scheduled observables', (done: DoneSignature) => { + it('should merge two immediately-scheduled observables', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [1, 2, 4, 3, 5, 6, 7, 8]; Observable.of>(a, b, queueScheduler).mergeAll().subscribe((val: number) => { - expect(val).toBe(r.shift()); + expect(val).to.equal(r.shift()); }, null, done); }); }); \ No newline at end of file diff --git a/spec/operators/mergeAll-spec.ts b/spec/operators/mergeAll-spec.ts index afb09f8f5f..837d2f1d84 100644 --- a/spec/operators/mergeAll-spec.ts +++ b/spec/operators/mergeAll-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -371,7 +371,7 @@ describe('Observable.prototype.mergeAll', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should merge all promises in an observable', (done: DoneSignature) => { + it('should merge all promises in an observable', (done: MochaDone) => { const e1 = Rx.Observable.from([ new Promise((res: any) => { res('a'); }), new Promise((res: any) => { res('b'); }), @@ -383,14 +383,14 @@ describe('Observable.prototype.mergeAll', () => { const res = []; (e1.mergeAll()).subscribe( (x: any) => { res.push(x); }, - (err: any) => { done.fail('should not be called'); }, + (err: any) => { done(new Error('should not be called')); }, () => { - expect(res).toEqual(expected); + expect(res).to.deep.equal(expected); done(); }); }); - it('should raise error when promise rejects', (done: DoneSignature) => { + it('should raise error when promise rejects', (done: MochaDone) => { const error = 'error'; const e1 = Rx.Observable.from([ new Promise((res: any) => { res('a'); }), @@ -403,10 +403,10 @@ describe('Observable.prototype.mergeAll', () => { (e1.mergeAll()).subscribe( (x: any) => { res.push(x); }, (err: any) => { - expect(res.length).toEqual(1); - expect(err).toBe(error); + expect(res.length).to.equal(1); + expect(err).to.equal('error'); done(); }, - () => { done.fail('should not be called'); }); + () => { done(new Error('should not be called')); }); }); -}); \ No newline at end of file +}); diff --git a/spec/operators/mergeMap-spec.ts b/spec/operators/mergeMap-spec.ts index 7f2ec77cde..0cc11ee0fa 100644 --- a/spec/operators/mergeMap-spec.ts +++ b/spec/operators/mergeMap-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature, type} from '../helpers/test-helper'; +declare const {hot, cold, expectObservable, expectSubscriptions, type}; const Observable = Rx.Observable; @@ -22,7 +22,7 @@ describe('Observable.prototype.mergeMap', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and merge', (done: DoneSignature) => { + it('should map values to constant resolved promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = (value: any) => Observable.from(Promise.resolve(42)); @@ -32,15 +32,15 @@ describe('Observable.prototype.mergeMap', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([42, 42, 42, 42]); + expect(results).to.deep.equal([42, 42, 42, 42]); done(); }); }); - it('should map values to constant rejected promises and merge', (done: DoneSignature) => { + it('should map values to constant rejected promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = function (value) { return Observable.from(Promise.reject(42)); @@ -48,18 +48,18 @@ describe('Observable.prototype.mergeMap', () => { source.mergeMap(project).subscribe( (x: number) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should map values to resolved promises and merge', (done: DoneSignature) => { + it('should map values to resolved promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = function (value, index) { return Observable.from(Promise.resolve(value + index)); @@ -71,15 +71,15 @@ describe('Observable.prototype.mergeMap', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([4, 4, 4, 4]); + expect(results).to.deep.equal([4, 4, 4, 4]); done(); }); }); - it('should map values to rejected promises and merge', (done: DoneSignature) => { + it('should map values to rejected promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = function (value, index) { return Observable.from(Promise.reject('' + value + '-' + index)); @@ -87,18 +87,18 @@ describe('Observable.prototype.mergeMap', () => { source.mergeMap(project).subscribe( (x: number) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual('4-0'); + expect(err).to.equal('4-0'); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should mergeMap values to resolved promises with resultSelector', (done: DoneSignature) => { + it('should mergeMap values to resolved promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const resultSelectorCalledWith = []; const project = function (value, index) { @@ -121,16 +121,16 @@ describe('Observable.prototype.mergeMap', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([8, 8, 8, 8]); - (expect(resultSelectorCalledWith)).toDeepEqual(expectedCalls); + expect(results).to.deep.equal([8, 8, 8, 8]); + expect(resultSelectorCalledWith).to.deep.equal(expectedCalls); done(); }); }); - it('should mergeMap values to rejected promises with resultSelector', (done: DoneSignature) => { + it('should mergeMap values to rejected promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const project = function (value, index) { return Observable.from(Promise.reject('' + value + '-' + index)); @@ -141,14 +141,14 @@ describe('Observable.prototype.mergeMap', () => { source.mergeMap(project, resultSelector).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual('4-0'); + expect(err).to.equal('4-0'); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); @@ -721,13 +721,13 @@ describe('Observable.prototype.mergeMap', () => { let completed = false; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); completed = true; }); - expect(completed).toBe(true); + expect(completed).to.be.true; }); it('should map and flatten an Array', () => { @@ -737,13 +737,13 @@ describe('Observable.prototype.mergeMap', () => { let completed = false; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); completed = true; }); - expect(completed).toBe(true); + expect(completed).to.be.true; }); it('should support type signatures', () => { diff --git a/spec/operators/mergeMapTo-spec.ts b/spec/operators/mergeMapTo-spec.ts index b931833249..7b6e645140 100644 --- a/spec/operators/mergeMapTo-spec.ts +++ b/spec/operators/mergeMapTo-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature, type} from '../helpers/test-helper'; +declare const {hot, cold, expectObservable, expectSubscriptions, type}; const Observable = Rx.Observable; @@ -26,7 +26,7 @@ describe('Observable.prototype.mergeMapTo', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should map values to constant resolved promises and merge', (done: DoneSignature) => { + it('should map values to constant resolved promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const results = []; @@ -35,31 +35,31 @@ describe('Observable.prototype.mergeMapTo', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([42, 42, 42, 42]); + expect(results).to.deep.equal([42, 42, 42, 42]); done(); }); }); - it('should map values to constant rejected promises and merge', (done: DoneSignature) => { + it('should map values to constant rejected promises and merge', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); source.mergeMapTo(Observable.from(Promise.reject(42))).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); - it('should mergeMapTo values to resolved promises with resultSelector', (done: DoneSignature) => { + it('should mergeMapTo values to resolved promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const resultSelectorCalledWith = []; const inner = Observable.from(Promise.resolve(42)); @@ -80,16 +80,16 @@ describe('Observable.prototype.mergeMapTo', () => { results.push(x); }, (err: any) => { - done.fail('Subscriber error handler not supposed to be called.'); + done(new Error('Subscriber error handler not supposed to be called.')); }, () => { - expect(results).toEqual([8, 8, 8, 8]); - (expect(resultSelectorCalledWith)).toDeepEqual(expectedCalls); + expect(results).to.deep.equal([8, 8, 8, 8]); + expect(resultSelectorCalledWith).to.deep.equal(expectedCalls); done(); }); }); - it('should mergeMapTo values to rejected promises with resultSelector', (done: DoneSignature) => { + it('should mergeMapTo values to rejected promises with resultSelector', (done: MochaDone) => { const source = Rx.Observable.from([4, 3, 2, 1]); const inner = Observable.from(Promise.reject(42)); const resultSelector = () => { @@ -98,14 +98,14 @@ describe('Observable.prototype.mergeMapTo', () => { source.mergeMapTo(inner, resultSelector).subscribe( (x: any) => { - done.fail('Subscriber next handler not supposed to be called.'); + done(new Error('Subscriber next handler not supposed to be called.')); }, (err: any) => { - expect(err).toEqual(42); + expect(err).to.equal(42); done(); }, () => { - done.fail('Subscriber complete handler not supposed to be called.'); + done(new Error('Subscriber complete handler not supposed to be called.')); }); }); @@ -412,13 +412,13 @@ describe('Observable.prototype.mergeMapTo', () => { let completed = false; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); completed = true; }); - expect(completed).toBe(true); + expect(completed).to.be.true; }); it('should map and flatten an Array', () => { @@ -428,13 +428,13 @@ describe('Observable.prototype.mergeMapTo', () => { let completed = false; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); completed = true; }); - expect(completed).toBe(true); + expect(completed).to.be.true; }); it('should support type signatures', () => { diff --git a/spec/operators/min-spec.ts b/spec/operators/min-spec.ts index e96a6a7ac4..8919019ae1 100644 --- a/spec/operators/min-spec.ts +++ b/spec/operators/min-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -69,34 +69,34 @@ describe('Observable.prototype.min', () => { expectSubscriptions(e1.subscriptions).toBe(subs); }); - it('should min a range() source observable', (done: DoneSignature) => { + it('should min a range() source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10000)).min().subscribe( (value: number) => { - expect(value).toEqual(1); + expect(value).to.equal(1); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should min a range().skip(1) source observable', (done: DoneSignature) => { + it('should min a range().skip(1) source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10)).skip(1).min().subscribe( (value: number) => { - expect(value).toEqual(2); + expect(value).to.equal(2); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should min a range().take(1) source observable', (done: DoneSignature) => { + it('should min a range().take(1) source observable', (done: MochaDone) => { (Rx.Observable.range(1, 10)).take(1).min().subscribe( (value: number) => { - expect(value).toEqual(1); + expect(value).to.equal(1); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/multicast-spec.ts b/spec/operators/multicast-spec.ts index 42cd9c6099..19596fe842 100644 --- a/spec/operators/multicast-spec.ts +++ b/spec/operators/multicast-spec.ts @@ -1,576 +1,576 @@ -import * as Rx from '../../dist/cjs/Rx'; -declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; - -const Observable = Rx.Observable; -const Subject = Rx.Subject; - -/** @test {multicast} */ -describe('Observable.prototype.multicast', () => { - asDiagram('multicast(() => new Subject())')('should mirror a simple source Observable', () => { - const source = cold('--1-2---3-4--5-|'); - const sourceSubs = '^ !'; - const multicasted = source.multicast(() => new Subject()); - const expected = '--1-2---3-4--5-|'; - - expectObservable(multicasted).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - it('should accept Subjects', (done: DoneSignature) => { - const expected = [1, 2, 3, 4]; - - const connectable = Observable.of(1, 2, 3, 4).multicast(new Subject()); - - connectable.subscribe((x: number) => { expect(x).toBe(expected.shift()); }, - (x) => { - done.fail('should not be called'); - }, () => { - done(); - }); - - connectable.connect(); - }); - - it('should accept Subject factory functions', (done: DoneSignature) => { - const expected = [1, 2, 3, 4]; - - const connectable = Observable.of(1, 2, 3, 4).multicast(() => new Subject()); - - connectable.subscribe((x: number) => { expect(x).toBe(expected.shift()); }, - (x) => { - done.fail('should not be called'); - }, () => { - done(); - }); - - connectable.connect(); - }); - - it('should do nothing if connect is not called, despite subscriptions', () => { - const source = cold('--1-2---3-4--5-|'); - const sourceSubs = []; - const multicasted = source.multicast(() => new Subject()); - const expected = '-'; - - expectObservable(multicasted).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should multicast the same values to multiple observers', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ !'; - const multicasted = source.multicast(() => new Subject()); - const subscriber1 = hot('a| ').mergeMapTo(multicasted); - const expected1 = '-1-2-3----4-|'; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const expected2 = ' -3----4-|'; - const subscriber3 = hot(' c| ').mergeMapTo(multicasted); - const expected3 = ' --4-|'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - it('should multicast an error from the source to multiple observers', () => { - const source = cold('-1-2-3----4-#'); - const sourceSubs = '^ !'; - const multicasted = source.multicast(() => new Subject()); - const subscriber1 = hot('a| ').mergeMapTo(multicasted); - const expected1 = '-1-2-3----4-#'; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const expected2 = ' -3----4-#'; - const subscriber3 = hot(' c| ').mergeMapTo(multicasted); - const expected3 = ' --4-#'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - it('should multicast the same values to multiple observers, ' + - 'but is unsubscribed explicitly and early', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ ! '; - const multicasted = source.multicast(() => new Subject()); - const unsub = ' u '; - const subscriber1 = hot('a| ').mergeMapTo(multicasted); - const expected1 = '-1-2-3---- '; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const expected2 = ' -3---- '; - const subscriber3 = hot(' c| ').mergeMapTo(multicasted); - const expected3 = ' -- '; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - // Set up unsubscription action - let connection; - expectObservable(hot(unsub).do(() => { - connection.unsubscribe(); - })).toBe(unsub); - - connection = multicasted.connect(); - }); - - it('should not break unsubscription chains when result is unsubscribed explicitly', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ ! '; - const multicasted = source - .mergeMap((x: string) => Observable.of(x)) - .multicast(() => new Subject()); - const subscriber1 = hot('a| ').mergeMapTo(multicasted); - const expected1 = '-1-2-3---- '; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const expected2 = ' -3---- '; - const subscriber3 = hot(' c| ').mergeMapTo(multicasted); - const expected3 = ' -- '; - const unsub = ' u '; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - // Set up unsubscription action - let connection; - expectObservable(hot(unsub).do(() => { - connection.unsubscribe(); - })).toBe(unsub); - - connection = multicasted.connect(); - }); - - it('should multicast an empty source', () => { - const source = cold('|'); - const sourceSubs = '(^!)'; - const multicasted = source.multicast(() => new Subject()); - const expected = '|'; - - expectObservable(multicasted).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - it('should multicast a never source', () => { - const source = cold('-'); - const sourceSubs = '^'; - const multicasted = source.multicast(() => new Subject()); - const expected = '-'; - - expectObservable(multicasted).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - it('should multicast a throw source', () => { - const source = cold('#'); - const sourceSubs = '(^!)'; - const multicasted = source.multicast(() => new Subject()); - const expected = '#'; - - expectObservable(multicasted).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - multicasted.connect(); - }); - - describe('with refCount() and subject factory', () => { - it('should connect when first subscriber subscribes', () => { - const source = cold( '-1-2-3----4-|'); - const sourceSubs = ' ^ !'; - const multicasted = source.multicast(() => new Subject()).refCount(); - const subscriber1 = hot(' a| ').mergeMapTo(multicasted); - const expected1 = ' -1-2-3----4-|'; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const expected2 = ' -3----4-|'; - const subscriber3 = hot(' c| ').mergeMapTo(multicasted); - const expected3 = ' --4-|'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should disconnect when last subscriber unsubscribes', () => { - const source = cold( '-1-2-3----4-|'); - const sourceSubs = ' ^ ! '; - const multicasted = source.multicast(() => new Subject()).refCount(); - const subscriber1 = hot(' a| ').mergeMapTo(multicasted); - const unsub1 = ' ! '; - const expected1 = ' -1-2-3-- '; - const subscriber2 = hot(' b| ').mergeMapTo(multicasted); - const unsub2 = ' ! '; - const expected2 = ' -3---- '; - - expectObservable(subscriber1, unsub1).toBe(expected1); - expectObservable(subscriber2, unsub2).toBe(expected2); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be retryable when cold source is synchronous', () => { - function subjectFactory() { return new Subject(); } - const source = cold('(123#)'); - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '(123123123123#) '; - const subscribe2 = ' s '; - const expected2 = ' (123123123123#)'; - const sourceSubs = ['(^!)', - '(^!)', - '(^!)', - '(^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)']; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.retry(3)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.retry(3)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be retryable with ReplaySubject and cold source is synchronous', () => { - function subjectFactory() { return new Rx.ReplaySubject(1); } - const source = cold('(123#)'); - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '(123123123123#) '; - const subscribe2 = ' s '; - const expected2 = ' (123123123123#)'; - const sourceSubs = ['(^!)', - '(^!)', - '(^!)', - '(^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)']; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.retry(3)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.retry(3)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be repeatable when cold source is synchronous', () => { - function subjectFactory() { return new Subject(); } - const source = cold('(123|)'); - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '(123123123123123|) '; - const subscribe2 = ' s '; - const expected2 = ' (123123123123123|)'; - const sourceSubs = ['(^!)', - '(^!)', - '(^!)', - '(^!)', - '(^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)']; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.repeat(5)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.repeat(5)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be repeatable with ReplaySubject and cold source is synchronous', () => { - function subjectFactory() { return new Rx.ReplaySubject(1); } - const source = cold('(123|)'); - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '(123123123123123|) '; - const subscribe2 = ' s '; - const expected2 = ' (123123123123123|)'; - const sourceSubs = ['(^!)', - '(^!)', - '(^!)', - '(^!)', - '(^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)', - ' (^!)']; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.repeat(5)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.repeat(5)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be retryable', () => { - function subjectFactory() { return new Subject(); } - const source = cold('-1-2-3----4-# '); - const sourceSubs = ['^ ! ', - ' ^ ! ', - ' ^ !']; - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-#'; - const subscribe2 = ' s '; - const expected2 = ' -3----4--1-2-3----4--1-2-3----4-#'; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.retry(2)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.retry(2)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be retryable using a ReplaySubject', () => { - function subjectFactory() { return new Rx.ReplaySubject(1); } - const source = cold('-1-2-3----4-# '); - const sourceSubs = ['^ ! ', - ' ^ ! ', - ' ^ !']; - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-#'; - const subscribe2 = ' s '; - const expected2 = ' 23----4--1-2-3----4--1-2-3----4-#'; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.retry(2)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.retry(2)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be repeatable', () => { - function subjectFactory() { return new Subject(); } - const source = cold('-1-2-3----4-| '); - const sourceSubs = ['^ ! ', - ' ^ ! ', - ' ^ !']; - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-|'; - const subscribe2 = ' s '; - const expected2 = ' -3----4--1-2-3----4--1-2-3----4-|'; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.repeat(3)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.repeat(3)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should be repeatable using a ReplaySubject', () => { - function subjectFactory() { return new Rx.ReplaySubject(1); } - const source = cold('-1-2-3----4-| '); - const sourceSubs = ['^ ! ', - ' ^ ! ', - ' ^ !']; - const multicasted = source.multicast(subjectFactory).refCount(); - const subscribe1 = 's '; - const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-|'; - const subscribe2 = ' s '; - const expected2 = ' 23----4--1-2-3----4--1-2-3----4-|'; - - expectObservable(hot(subscribe1).do(() => { - expectObservable(multicasted.repeat(3)).toBe(expected1); - })).toBe(subscribe1); - - expectObservable(hot(subscribe2).do(() => { - expectObservable(multicasted.repeat(3)).toBe(expected2); - })).toBe(subscribe2); - - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - }); - - it('should multicast one observable to multiple observers', (done: DoneSignature) => { - const results1 = []; - const results2 = []; - let subscriptions = 0; - - const source = new Observable((observer: Rx.Observer) => { - subscriptions++; - observer.next(1); - observer.next(2); - observer.next(3); - observer.next(4); - observer.complete(); - }); - - const connectable = source.multicast(() => { - return new Subject(); - }); - - connectable.subscribe((x: number) => { - results1.push(x); - }); - - connectable.subscribe((x: number) => { - results2.push(x); - }); - - expect(results1).toEqual([]); - expect(results2).toEqual([]); - - connectable.connect(); - - expect(results1).toEqual([1, 2, 3, 4]); - expect(results1).toEqual([1, 2, 3, 4]); - expect(subscriptions).toBe(1); - done(); - }); - - it('should remove all subscribers from the subject when disconnected', (done: DoneSignature) => { - const subject = new Subject(); - const expected = [1, 2, 3, 4]; - let i = 0; - - const source = Observable.from([1, 2, 3, 4]).multicast(subject); - - source.subscribe((x: number) => { - expect(x).toBe(expected[i++]); - }, null, () => { - expect(subject.isUnsubscribed).toBe(true); - done(); - }); - - source.connect(); - }); - - describe('when given a subject factory', () => { - it('should allow you to reconnect by subscribing again', (done: DoneSignature) => { - const expected = [1, 2, 3, 4]; - let i = 0; - - const source = Observable.of(1, 2, 3, 4).multicast(() => new Subject()); - - source.subscribe((x: number) => { - expect(x).toBe(expected[i++]); - }, null, - () => { - i = 0; - - source.subscribe((x: number) => { - expect(x).toBe(expected[i++]); - }, null, done); - - source.connect(); - }); - - source.connect(); - }); - - it('should not throw ObjectUnsubscribedError when used in ' + - 'a switchMap', (done: DoneSignature) => { - const source = Observable.of(1, 2, 3) - .multicast(() => new Subject()) - .refCount(); - - const expected = ['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']; - - Observable.of('a', 'b', 'c') - .switchMap((letter: string) => source.map((n: number) => String(letter + n))) - .subscribe((x: string) => { - expect(x).toBe(expected.shift()); - }, (x) => { - done.fail('should not be called'); - }, () => { - expect(expected.length).toBe(0); - done(); - }); - }); - }); - - describe('when given a subject', () => { - it('should NOT allow you to reconnect by subscribing again', (done: DoneSignature) => { - const expected = [1, 2, 3, 4]; - let i = 0; - - const source = Observable.of(1, 2, 3, 4).multicast(new Subject()); - - source.subscribe((x: number) => { - expect(x).toBe(expected[i++]); - }, - null, - () => { - source.subscribe((x: number) => { - done.fail('should not be called'); - }, null, () => { - done(); - }); - - source.connect(); - }); - - source.connect(); - }); - - it('should not throw ObjectUnsubscribedError when used in ' + - 'a switchMap', (done: DoneSignature) => { - const source = Observable.of(1, 2, 3) - .multicast(new Subject()) - .refCount(); - - const expected = ['a1', 'a2', 'a3']; - - Observable.of('a', 'b', 'c') - .switchMap((letter: string) => source.map((n: number) => String(letter + n))) - .subscribe((x: string) => { - expect(x).toBe(expected.shift()); - }, (x) => { - done.fail('should not be called'); - }, () => { - expect(expected.length).toBe(0); - done(); - }); - }); - }); -}); +import {expect} from 'chai'; +import * as Rx from '../../dist/cjs/Rx'; +declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; + +const Observable = Rx.Observable; +const Subject = Rx.Subject; + +/** @test {multicast} */ +describe('Observable.prototype.multicast', () => { + asDiagram('multicast(() => new Subject())')('should mirror a simple source Observable', () => { + const source = cold('--1-2---3-4--5-|'); + const sourceSubs = '^ !'; + const multicasted = source.multicast(() => new Subject()); + const expected = '--1-2---3-4--5-|'; + + expectObservable(multicasted).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + it('should accept Subjects', (done: MochaDone) => { + const expected = [1, 2, 3, 4]; + + const connectable = Observable.of(1, 2, 3, 4).multicast(new Subject()); + + connectable.subscribe((x: number) => { expect(x).to.equal(expected.shift()); }, + (x) => { + done(new Error('should not be called')); + }, () => { + done(); + }); + + connectable.connect(); + }); + + it('should accept Subject factory functions', (done: MochaDone) => { + const expected = [1, 2, 3, 4]; + + const connectable = Observable.of(1, 2, 3, 4).multicast(() => new Subject()); + + connectable.subscribe((x: number) => { expect(x).to.equal(expected.shift()); }, + (x) => { + done(new Error('should not be called')); + }, () => { + done(); + }); + + connectable.connect(); + }); + + it('should do nothing if connect is not called, despite subscriptions', () => { + const source = cold('--1-2---3-4--5-|'); + const sourceSubs = []; + const multicasted = source.multicast(() => new Subject()); + const expected = '-'; + + expectObservable(multicasted).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should multicast the same values to multiple observers', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ !'; + const multicasted = source.multicast(() => new Subject()); + const subscriber1 = hot('a| ').mergeMapTo(multicasted); + const expected1 = '-1-2-3----4-|'; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const expected2 = ' -3----4-|'; + const subscriber3 = hot(' c| ').mergeMapTo(multicasted); + const expected3 = ' --4-|'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + it('should multicast an error from the source to multiple observers', () => { + const source = cold('-1-2-3----4-#'); + const sourceSubs = '^ !'; + const multicasted = source.multicast(() => new Subject()); + const subscriber1 = hot('a| ').mergeMapTo(multicasted); + const expected1 = '-1-2-3----4-#'; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const expected2 = ' -3----4-#'; + const subscriber3 = hot(' c| ').mergeMapTo(multicasted); + const expected3 = ' --4-#'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + it('should multicast the same values to multiple observers, ' + + 'but is unsubscribed explicitly and early', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ ! '; + const multicasted = source.multicast(() => new Subject()); + const unsub = ' u '; + const subscriber1 = hot('a| ').mergeMapTo(multicasted); + const expected1 = '-1-2-3---- '; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const expected2 = ' -3---- '; + const subscriber3 = hot(' c| ').mergeMapTo(multicasted); + const expected3 = ' -- '; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + // Set up unsubscription action + let connection; + expectObservable(hot(unsub).do(() => { + connection.unsubscribe(); + })).toBe(unsub); + + connection = multicasted.connect(); + }); + + it('should not break unsubscription chains when result is unsubscribed explicitly', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ ! '; + const multicasted = source + .mergeMap((x: string) => Observable.of(x)) + .multicast(() => new Subject()); + const subscriber1 = hot('a| ').mergeMapTo(multicasted); + const expected1 = '-1-2-3---- '; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const expected2 = ' -3---- '; + const subscriber3 = hot(' c| ').mergeMapTo(multicasted); + const expected3 = ' -- '; + const unsub = ' u '; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + // Set up unsubscription action + let connection; + expectObservable(hot(unsub).do(() => { + connection.unsubscribe(); + })).toBe(unsub); + + connection = multicasted.connect(); + }); + + it('should multicast an empty source', () => { + const source = cold('|'); + const sourceSubs = '(^!)'; + const multicasted = source.multicast(() => new Subject()); + const expected = '|'; + + expectObservable(multicasted).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + it('should multicast a never source', () => { + const source = cold('-'); + const sourceSubs = '^'; + const multicasted = source.multicast(() => new Subject()); + const expected = '-'; + + expectObservable(multicasted).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + it('should multicast a throw source', () => { + const source = cold('#'); + const sourceSubs = '(^!)'; + const multicasted = source.multicast(() => new Subject()); + const expected = '#'; + + expectObservable(multicasted).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + multicasted.connect(); + }); + + describe('with refCount() and subject factory', () => { + it('should connect when first subscriber subscribes', () => { + const source = cold( '-1-2-3----4-|'); + const sourceSubs = ' ^ !'; + const multicasted = source.multicast(() => new Subject()).refCount(); + const subscriber1 = hot(' a| ').mergeMapTo(multicasted); + const expected1 = ' -1-2-3----4-|'; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const expected2 = ' -3----4-|'; + const subscriber3 = hot(' c| ').mergeMapTo(multicasted); + const expected3 = ' --4-|'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should disconnect when last subscriber unsubscribes', () => { + const source = cold( '-1-2-3----4-|'); + const sourceSubs = ' ^ ! '; + const multicasted = source.multicast(() => new Subject()).refCount(); + const subscriber1 = hot(' a| ').mergeMapTo(multicasted); + const unsub1 = ' ! '; + const expected1 = ' -1-2-3-- '; + const subscriber2 = hot(' b| ').mergeMapTo(multicasted); + const unsub2 = ' ! '; + const expected2 = ' -3---- '; + + expectObservable(subscriber1, unsub1).toBe(expected1); + expectObservable(subscriber2, unsub2).toBe(expected2); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be retryable when cold source is synchronous', () => { + function subjectFactory() { return new Subject(); } + const source = cold('(123#)'); + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '(123123123123#) '; + const subscribe2 = ' s '; + const expected2 = ' (123123123123#)'; + const sourceSubs = ['(^!)', + '(^!)', + '(^!)', + '(^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)']; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.retry(3)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.retry(3)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be retryable with ReplaySubject and cold source is synchronous', () => { + function subjectFactory() { return new Rx.ReplaySubject(1); } + const source = cold('(123#)'); + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '(123123123123#) '; + const subscribe2 = ' s '; + const expected2 = ' (123123123123#)'; + const sourceSubs = ['(^!)', + '(^!)', + '(^!)', + '(^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)']; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.retry(3)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.retry(3)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be repeatable when cold source is synchronous', () => { + function subjectFactory() { return new Subject(); } + const source = cold('(123|)'); + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '(123123123123123|) '; + const subscribe2 = ' s '; + const expected2 = ' (123123123123123|)'; + const sourceSubs = ['(^!)', + '(^!)', + '(^!)', + '(^!)', + '(^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)']; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.repeat(5)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.repeat(5)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be repeatable with ReplaySubject and cold source is synchronous', () => { + function subjectFactory() { return new Rx.ReplaySubject(1); } + const source = cold('(123|)'); + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '(123123123123123|) '; + const subscribe2 = ' s '; + const expected2 = ' (123123123123123|)'; + const sourceSubs = ['(^!)', + '(^!)', + '(^!)', + '(^!)', + '(^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)', + ' (^!)']; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.repeat(5)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.repeat(5)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be retryable', () => { + function subjectFactory() { return new Subject(); } + const source = cold('-1-2-3----4-# '); + const sourceSubs = ['^ ! ', + ' ^ ! ', + ' ^ !']; + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-#'; + const subscribe2 = ' s '; + const expected2 = ' -3----4--1-2-3----4--1-2-3----4-#'; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.retry(2)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.retry(2)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be retryable using a ReplaySubject', () => { + function subjectFactory() { return new Rx.ReplaySubject(1); } + const source = cold('-1-2-3----4-# '); + const sourceSubs = ['^ ! ', + ' ^ ! ', + ' ^ !']; + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-#'; + const subscribe2 = ' s '; + const expected2 = ' 23----4--1-2-3----4--1-2-3----4-#'; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.retry(2)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.retry(2)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be repeatable', () => { + function subjectFactory() { return new Subject(); } + const source = cold('-1-2-3----4-| '); + const sourceSubs = ['^ ! ', + ' ^ ! ', + ' ^ !']; + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-|'; + const subscribe2 = ' s '; + const expected2 = ' -3----4--1-2-3----4--1-2-3----4-|'; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.repeat(3)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.repeat(3)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should be repeatable using a ReplaySubject', () => { + function subjectFactory() { return new Rx.ReplaySubject(1); } + const source = cold('-1-2-3----4-| '); + const sourceSubs = ['^ ! ', + ' ^ ! ', + ' ^ !']; + const multicasted = source.multicast(subjectFactory).refCount(); + const subscribe1 = 's '; + const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-|'; + const subscribe2 = ' s '; + const expected2 = ' 23----4--1-2-3----4--1-2-3----4-|'; + + expectObservable(hot(subscribe1).do(() => { + expectObservable(multicasted.repeat(3)).toBe(expected1); + })).toBe(subscribe1); + + expectObservable(hot(subscribe2).do(() => { + expectObservable(multicasted.repeat(3)).toBe(expected2); + })).toBe(subscribe2); + + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + }); + + it('should multicast one observable to multiple observers', (done: MochaDone) => { + const results1 = []; + const results2 = []; + let subscriptions = 0; + + const source = new Observable((observer: Rx.Observer) => { + subscriptions++; + observer.next(1); + observer.next(2); + observer.next(3); + observer.next(4); + observer.complete(); + }); + + const connectable = source.multicast(() => { + return new Subject(); + }); + + connectable.subscribe((x: number) => { + results1.push(x); + }); + + connectable.subscribe((x: number) => { + results2.push(x); + }); + + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); + + connectable.connect(); + + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(subscriptions).to.equal(1); + done(); + }); + + it('should remove all subscribers from the subject when disconnected', (done: MochaDone) => { + const subject = new Subject(); + const expected = [1, 2, 3, 4]; + let i = 0; + + const source = Observable.from([1, 2, 3, 4]).multicast(subject); + + source.subscribe((x: number) => { + expect(x).to.equal(expected[i++]); + }, null, () => { + expect(subject.isUnsubscribed).to.be.true; + done(); + }); + + source.connect(); + }); + + describe('when given a subject factory', () => { + it('should allow you to reconnect by subscribing again', (done: MochaDone) => { + const expected = [1, 2, 3, 4]; + let i = 0; + + const source = Observable.of(1, 2, 3, 4).multicast(() => new Subject()); + + source.subscribe((x: number) => { + expect(x).to.equal(expected[i++]); + }, null, + () => { + i = 0; + + source.subscribe((x: number) => { + expect(x).to.equal(expected[i++]); + }, null, done); + + source.connect(); + }); + + source.connect(); + }); + + it('should not throw ObjectUnsubscribedError when used in ' + + 'a switchMap', (done: MochaDone) => { + const source = Observable.of(1, 2, 3) + .multicast(() => new Subject()) + .refCount(); + + const expected = ['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']; + + Observable.of('a', 'b', 'c') + .switchMap((letter: string) => source.map((n: number) => String(letter + n))) + .subscribe((x: string) => { + expect(x).to.equal(expected.shift()); + }, (x) => { + done(new Error('should not be called')); + }, () => { + expect(expected.length).to.equal(0); + done(); + }); + }); + }); + + describe('when given a subject', () => { + it('should NOT allow you to reconnect by subscribing again', (done: MochaDone) => { + const expected = [1, 2, 3, 4]; + let i = 0; + + const source = Observable.of(1, 2, 3, 4).multicast(new Subject()); + + source.subscribe((x: number) => { + expect(x).to.equal(expected[i++]); + }, + null, + () => { + source.subscribe((x: number) => { + done(new Error('should not be called')); + }, null, () => { + done(); + }); + + expect(() => source.connect()).to.throw(Rx.ObjectUnsubscribedError); + }); + + source.connect(); + }); + + it('should not throw ObjectUnsubscribedError when used in ' + + 'a switchMap', (done: MochaDone) => { + const source = Observable.of(1, 2, 3) + .multicast(new Subject()) + .refCount(); + + const expected = ['a1', 'a2', 'a3']; + + Observable.of('a', 'b', 'c') + .switchMap((letter: string) => source.map((n: number) => String(letter + n))) + .subscribe((x: string) => { + expect(x).to.equal(expected.shift()); + }, (x) => { + done(new Error('should not be called')); + }, () => { + expect(expected.length).to.equal(0); + done(); + }); + }); + }); +}); diff --git a/spec/operators/partition-spec.ts b/spec/operators/partition-spec.ts index b7bc01fb10..38be5734aa 100644 --- a/spec/operators/partition-spec.ts +++ b/spec/operators/partition-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -222,6 +223,6 @@ describe('Observable.prototype.partition', () => { it('should throw without predicate', () => { const e1 = hot('--a-b---a------d----'); - expect(e1.partition).toThrow(); + expect(e1.partition).to.throw(); }); }); \ No newline at end of file diff --git a/spec/operators/pluck-spec.ts b/spec/operators/pluck-spec.ts index f54f983fa7..ff0619d58d 100644 --- a/spec/operators/pluck-spec.ts +++ b/spec/operators/pluck-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {cold, expectObservable, expectSubscriptions}; @@ -70,7 +71,7 @@ describe('Observable.prototype.pluck', () => { it('should throw an error if not property is passed', () => { expect(() => { Observable.of({prop: 1}, {prop: 2}).pluck(); - }).toThrow(new Error('List of properties cannot be empty.')); + }).to.throw(Error, 'List of properties cannot be empty.'); }); it('should propagate errors from observable that emits only errors', () => { @@ -102,7 +103,7 @@ describe('Observable.prototype.pluck', () => { const r = a .pluck('whatever') .do(null, null, () => { - expect(invoked).toBe(0); + expect(invoked).to.equal(0); }); expectObservable(r).toBe(expected); diff --git a/spec/operators/publish-spec.ts b/spec/operators/publish-spec.ts index df90f26d58..ba4784bab1 100644 --- a/spec/operators/publish-spec.ts +++ b/spec/operators/publish-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -18,21 +18,21 @@ describe('Observable.prototype.publish', () => { published.connect(); }); - it('To match RxJS 4 behavior, it should NOT allow you to reconnect by subscribing again', (done: DoneSignature) => { + it('To match RxJS 4 behavior, it should NOT allow you to reconnect by subscribing again', (done: MochaDone) => { const expected = [1, 2, 3, 4]; let i = 0; const source = Observable.of(1, 2, 3, 4).publish(); source.subscribe((x: number) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { source.subscribe((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -40,12 +40,12 @@ describe('Observable.prototype.publish', () => { source.connect(); }); - expect(() => source.connect()).toThrow(new Rx.ObjectUnsubscribedError()); + expect(() => source.connect()).to.throw(Rx.ObjectUnsubscribedError); }); it('should return a ConnectableObservable', () => { const source = Observable.of(1).publish(); - expect(source instanceof Rx.ConnectableObservable).toBe(true); + expect(source instanceof Rx.ConnectableObservable).to.be.true; }); it('should do nothing if connect is not called, despite subscriptions', () => { @@ -220,7 +220,7 @@ describe('Observable.prototype.publish', () => { }); }); - it('should emit completed when subscribed after completed', (done: DoneSignature) => { + it('should emit completed when subscribed after completed', (done: MochaDone) => { const results1 = []; const results2 = []; let subscriptions = 0; @@ -240,21 +240,21 @@ describe('Observable.prototype.publish', () => { results1.push(x); }); - expect(results1).toEqual([]); - expect(results2).toEqual([]); + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); connectable.connect(); - expect(results1).toEqual([1, 2, 3, 4]); - expect(results2).toEqual([]); - expect(subscriptions).toBe(1); + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results2).to.deep.equal([]); + expect(subscriptions).to.equal(1); connectable.subscribe((x: any) => { results2.push(x); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(results2).toEqual([]); + expect(results2).to.deep.equal([]); done(); }); }); @@ -295,7 +295,7 @@ describe('Observable.prototype.publish', () => { published.connect(); }); - it('should multicast one observable to multiple observers', (done: DoneSignature) => { + it('should multicast one observable to multiple observers', (done: MochaDone) => { const results1 = []; const results2 = []; let subscriptions = 0; @@ -319,14 +319,14 @@ describe('Observable.prototype.publish', () => { results2.push(x); }); - expect(results1).toEqual([]); - expect(results2).toEqual([]); + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); connectable.connect(); - expect(results1).toEqual([1, 2, 3, 4]); - expect(results2).toEqual([1, 2, 3, 4]); - expect(subscriptions).toBe(1); + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results2).to.deep.equal([1, 2, 3, 4]); + expect(subscriptions).to.equal(1); done(); }); }); \ No newline at end of file diff --git a/spec/operators/publishBehavior-spec.ts b/spec/operators/publishBehavior-spec.ts index 21abf138c7..3fcb37bf10 100644 --- a/spec/operators/publishBehavior-spec.ts +++ b/spec/operators/publishBehavior-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -20,7 +20,7 @@ describe('Observable.prototype.publishBehavior', () => { it('should return a ConnectableObservable', () => { const source = Observable.of(1).publishBehavior(1); - expect(source instanceof Rx.ConnectableObservable).toBe(true); + expect(source instanceof Rx.ConnectableObservable).to.be.true; }); it('should only emit default value if connect is not called, despite subscriptions', () => { @@ -33,7 +33,7 @@ describe('Observable.prototype.publishBehavior', () => { expectSubscriptions(source.subscriptions).toBe(sourceSubs); }); - it('should follow the RxJS 4 behavior and NOT allow you to reconnect by subscribing again', (done: DoneSignature) => { + it('should follow the RxJS 4 behavior and NOT allow you to reconnect by subscribing again', (done: MochaDone) => { const expected = [0, 1, 2, 3, 4]; let i = 0; @@ -41,22 +41,23 @@ describe('Observable.prototype.publishBehavior', () => { source.subscribe( (x: number) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { source.subscribe((x: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); source.connect(); }); - expect(() => source.connect()).toThrow(new Rx.ObjectUnsubscribedError()); + + expect(() => source.connect()).to.throw(Rx.ObjectUnsubscribedError); }); it('should multicast the same values to multiple observers', () => { @@ -221,7 +222,7 @@ describe('Observable.prototype.publishBehavior', () => { }); }); - it('should emit completed when subscribed after completed', (done: DoneSignature) => { + it('should emit completed when subscribed after completed', (done: MochaDone) => { const results1 = []; const results2 = []; let subscriptions = 0; @@ -241,21 +242,21 @@ describe('Observable.prototype.publishBehavior', () => { results1.push(x); }); - expect(results1).toEqual([0]); - expect(results2).toEqual([]); + expect(results1).to.deep.equal([0]); + expect(results2).to.deep.equal([]); connectable.connect(); - expect(results1).toEqual([0, 1, 2, 3, 4]); - expect(results2).toEqual([]); - expect(subscriptions).toBe(1); + expect(results1).to.deep.equal([0, 1, 2, 3, 4]); + expect(results2).to.deep.equal([]); + expect(subscriptions).to.equal(1); connectable.subscribe(function (x) { results2.push(x); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(results2).toEqual([]); + expect(results2).to.deep.equal([]); done(); }); }); @@ -296,7 +297,7 @@ describe('Observable.prototype.publishBehavior', () => { published.connect(); }); - it('should multicast one observable to multiple observers', (done: DoneSignature) => { + it('should multicast one observable to multiple observers', (done: MochaDone) => { const results1 = []; const results2 = []; let subscriptions = 0; @@ -315,23 +316,23 @@ describe('Observable.prototype.publishBehavior', () => { results1.push(x); }); - expect(results1).toEqual([0]); + expect(results1).to.deep.equal([0]); connectable.connect(); - expect(results2).toEqual([]); + expect(results2).to.deep.equal([]); connectable.subscribe((x: any) => { results2.push(x); }); - expect(results1).toEqual([0, 1, 2, 3, 4]); - expect(results2).toEqual([4]); - expect(subscriptions).toBe(1); + expect(results1).to.deep.equal([0, 1, 2, 3, 4]); + expect(results2).to.deep.equal([4]); + expect(subscriptions).to.equal(1); done(); }); - it('should follow the RxJS 4 behavior and emit nothing to observer after completed', (done: DoneSignature) => { + it('should follow the RxJS 4 behavior and emit nothing to observer after completed', (done: MochaDone) => { const results = []; const source = new Observable((observer: Rx.Observer) => { @@ -350,7 +351,7 @@ describe('Observable.prototype.publishBehavior', () => { results.push(x); }); - expect(results).toEqual([]); + expect(results).to.deep.equal([]); done(); }); }); \ No newline at end of file diff --git a/spec/operators/publishLast-spec.ts b/spec/operators/publishLast-spec.ts index d58e2901bd..c956182dd2 100644 --- a/spec/operators/publishLast-spec.ts +++ b/spec/operators/publishLast-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -21,7 +21,7 @@ describe('Observable.prototype.publishLast', () => { it('should return a ConnectableObservable', () => { const source = Observable.of(1).publishLast(); - expect(source instanceof Rx.ConnectableObservable).toBe(true); + expect(source instanceof Rx.ConnectableObservable).to.be.true; }); it('should do nothing if connect is not called, despite subscriptions', () => { @@ -215,7 +215,7 @@ describe('Observable.prototype.publishLast', () => { published.connect(); }); - it('should multicast one observable to multiple observers', (done: DoneSignature) => { + it('should multicast one observable to multiple observers', (done: MochaDone) => { const results1 = []; const results2 = []; let subscriptions = 0; @@ -239,14 +239,14 @@ describe('Observable.prototype.publishLast', () => { results2.push(x); }); - expect(results1).toEqual([]); - expect(results2).toEqual([]); + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); connectable.connect(); - expect(results1).toEqual([4]); - expect(results2).toEqual([4]); - expect(subscriptions).toBe(1); + expect(results1).to.deep.equal([4]); + expect(results2).to.deep.equal([4]); + expect(subscriptions).to.equal(1); done(); }); }); \ No newline at end of file diff --git a/spec/operators/publishReplay-spec.ts b/spec/operators/publishReplay-spec.ts index ba67481c20..17268a2aed 100644 --- a/spec/operators/publishReplay-spec.ts +++ b/spec/operators/publishReplay-spec.ts @@ -1,393 +1,391 @@ -import * as Rx from '../../dist/cjs/Rx'; -declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; - -const Observable = Rx.Observable; - -/** @test {publishReplay} */ -describe('Observable.prototype.publishReplay', () => { - asDiagram('publishReplay(1)')('should mirror a simple source Observable', () => { - const source = cold('--1-2---3-4--5-|'); - const sourceSubs = '^ !'; - const published = source.publishReplay(1); - const expected = '--1-2---3-4--5-|'; - - expectObservable(published).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should return a ConnectableObservable', () => { - const source = Observable.of(1).publishReplay(); - expect(source instanceof Rx.ConnectableObservable).toBe(true); - }); - - it('should do nothing if connect is not called, despite subscriptions', () => { - const source = cold('--1-2---3-4--5-|'); - const sourceSubs = []; - const published = source.publishReplay(1); - const expected = '-'; - - expectObservable(published).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should multicast the same values to multiple observers, bufferSize=1', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ !'; - const published = source.publishReplay(1); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3----4-|'; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23----4-|'; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3-4-|'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should multicast the same values to multiple observers, bufferSize=2', () => { - const source = cold('-1-2-----3------4-|'); - const sourceSubs = '^ !'; - const published = source.publishReplay(2); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-----3------4-|'; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' (12)-3------4-|'; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' (23)-4-|'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should multicast an error from the source to multiple observers', () => { - const source = cold('-1-2-3----4-#'); - const sourceSubs = '^ !'; - const published = source.publishReplay(1); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3----4-#'; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23----4-#'; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3-4-#'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should multicast the same values to multiple observers, ' + - 'but is unsubscribed explicitly and early', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ ! '; - const published = source.publishReplay(1); - const unsub = ' u '; - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3---- '; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23---- '; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3- '; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - // Set up unsubscription action - let connection; - expectObservable(hot(unsub).do(() => { - connection.unsubscribe(); - })).toBe(unsub); - - connection = published.connect(); - }); - - it('should not break unsubscription chains when result is unsubscribed explicitly', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ ! '; - const published = source - .mergeMap((x: any) => Observable.of(x)) - .publishReplay(1); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3---- '; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23---- '; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3- '; - const unsub = ' u '; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - // Set up unsubscription action - let connection; - expectObservable(hot(unsub).do(() => { - connection.unsubscribe(); - })).toBe(unsub); - - connection = published.connect(); - }); - - describe('with refCount()', () => { - it('should connect when first subscriber subscribes', () => { - const source = cold( '-1-2-3----4-|'); - const sourceSubs = ' ^ !'; - const replayed = source.publishReplay(1).refCount(); - const subscriber1 = hot(' a| ').mergeMapTo(replayed); - const expected1 = ' -1-2-3----4-|'; - const subscriber2 = hot(' b| ').mergeMapTo(replayed); - const expected2 = ' 23----4-|'; - const subscriber3 = hot(' c| ').mergeMapTo(replayed); - const expected3 = ' 3-4-|'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should disconnect when last subscriber unsubscribes', () => { - const source = cold( '-1-2-3----4-|'); - const sourceSubs = ' ^ ! '; - const replayed = source.publishReplay(1).refCount(); - const subscriber1 = hot(' a| ').mergeMapTo(replayed); - const unsub1 = ' ! '; - const expected1 = ' -1-2-3-- '; - const subscriber2 = hot(' b| ').mergeMapTo(replayed); - const unsub2 = ' ! '; - const expected2 = ' 23---- '; - - expectObservable(subscriber1, unsub1).toBe(expected1); - expectObservable(subscriber2, unsub2).toBe(expected2); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should NOT be retryable', () => { - const source = cold('-1-2-3----4-#'); - const sourceSubs = '^ !'; - const published = source.publishReplay(1).refCount().retry(3); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3----4-(444#)'; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23----4-(444#)'; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3-4-(444#)'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - - it('should NOT be repeatable', () => { - const source = cold('-1-2-3----4-|'); - const sourceSubs = '^ !'; - const published = source.publishReplay(1).refCount().repeat(3); - const subscriber1 = hot('a| ').mergeMapTo(published); - const expected1 = '-1-2-3----4-(44|)'; - const subscriber2 = hot(' b| ').mergeMapTo(published); - const expected2 = ' 23----4-(44|)'; - const subscriber3 = hot(' c| ').mergeMapTo(published); - const expected3 = ' 3-4-(44|)'; - - expectObservable(subscriber1).toBe(expected1); - expectObservable(subscriber2).toBe(expected2); - expectObservable(subscriber3).toBe(expected3); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - }); - }); - - it('should multicast one observable to multiple observers', (done: DoneSignature) => { - const results1 = []; - const results2 = []; - let subscriptions = 0; - - const source = new Observable((observer: Rx.Observer) => { - subscriptions++; - observer.next(1); - observer.next(2); - observer.next(3); - observer.next(4); - observer.complete(); - }); - - const connectable = source.publishReplay(); - - connectable.subscribe((x: number) => { - results1.push(x); - }); - connectable.subscribe((x: number) => { - results2.push(x); - }); - - expect(results1).toEqual([]); - expect(results2).toEqual([]); - - connectable.connect(); - - expect(results1).toEqual([1, 2, 3, 4]); - expect(results2).toEqual([1, 2, 3, 4]); - expect(subscriptions).toBe(1); - done(); - }); - - it('should replay as many events as specified by the bufferSize', (done: DoneSignature) => { - const results1 = []; - const results2 = []; - let subscriptions = 0; - - const source = new Observable((observer: Rx.Observer) => { - subscriptions++; - observer.next(1); - observer.next(2); - observer.next(3); - observer.next(4); - observer.complete(); - }); - - const connectable = source.publishReplay(2); - - connectable.subscribe((x: number) => { - results1.push(x); - }); - - expect(results1).toEqual([]); - expect(results2).toEqual([]); - - connectable.connect(); - - connectable.subscribe((x: number) => { - results2.push(x); - }); - - expect(results1).toEqual([1, 2, 3, 4]); - expect(results2).toEqual([3, 4]); - expect(subscriptions).toBe(1); - done(); - }); - - it('should emit replayed values plus completed when subscribed after completed', (done: DoneSignature) => { - const results1 = []; - const results2 = []; - let subscriptions = 0; - - const source = new Observable((observer: Rx.Observer) => { - subscriptions++; - observer.next(1); - observer.next(2); - observer.next(3); - observer.next(4); - observer.complete(); - }); - - const connectable = source.publishReplay(2); - - connectable.subscribe((x: number) => { - results1.push(x); - }); - - expect(results1).toEqual([]); - expect(results2).toEqual([]); - - connectable.connect(); - - expect(results1).toEqual([1, 2, 3, 4]); - expect(results2).toEqual([]); - expect(subscriptions).toBe(1); - - connectable.subscribe((x: number) => { - results2.push(x); - }, (x) => { - done.fail('should not be called'); - }, () => { - expect(results2).toEqual([3, 4]); - done(); - }); - }); - - it('should multicast an empty source', () => { - const source = cold('|'); - const sourceSubs = '(^!)'; - const published = source.publishReplay(1); - const expected = '|'; - - expectObservable(published).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should multicast a never source', () => { - const source = cold('-'); - const sourceSubs = '^'; - - const published = source.publishReplay(1); - const expected = '-'; - - expectObservable(published).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should multicast a throw source', () => { - const source = cold('#'); - const sourceSubs = '(^!)'; - const published = source.publishReplay(1); - const expected = '#'; - - expectObservable(published).toBe(expected); - expectSubscriptions(source.subscriptions).toBe(sourceSubs); - - published.connect(); - }); - - it('should follow the RxJS 4 behavior and NOT allow you to reconnect by subscribing again', (done: DoneSignature) => { - const expected = [1, 2, 3, 4]; - let i = 0; - - const source = Observable.of(1, 2, 3, 4).publishReplay(1); - - const results = []; - - source.subscribe( - (x: number) => { - expect(x).toBe(expected[i++]); - }, (x) => { - done.fail('should not be called'); - }, () => { - i = 0; - - source.subscribe((x: number) => { - results.push(x); - }, (x) => { - done.fail('should not be called'); - }, () => { - done(); - }); - - source.connect(); - }); - - source.connect(); - - expect(results).toEqual([4]); - }); +import {expect} from 'chai'; +import * as Rx from '../../dist/cjs/Rx'; +declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; + +const Observable = Rx.Observable; + +/** @test {publishReplay} */ +describe('Observable.prototype.publishReplay', () => { + asDiagram('publishReplay(1)')('should mirror a simple source Observable', () => { + const source = cold('--1-2---3-4--5-|'); + const sourceSubs = '^ !'; + const published = source.publishReplay(1); + const expected = '--1-2---3-4--5-|'; + + expectObservable(published).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should return a ConnectableObservable', () => { + const source = Observable.of(1).publishReplay(); + expect(source instanceof Rx.ConnectableObservable).to.be.true; + }); + + it('should do nothing if connect is not called, despite subscriptions', () => { + const source = cold('--1-2---3-4--5-|'); + const sourceSubs = []; + const published = source.publishReplay(1); + const expected = '-'; + + expectObservable(published).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should multicast the same values to multiple observers, bufferSize=1', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ !'; + const published = source.publishReplay(1); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3----4-|'; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23----4-|'; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3-4-|'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should multicast the same values to multiple observers, bufferSize=2', () => { + const source = cold('-1-2-----3------4-|'); + const sourceSubs = '^ !'; + const published = source.publishReplay(2); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-----3------4-|'; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' (12)-3------4-|'; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' (23)-4-|'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should multicast an error from the source to multiple observers', () => { + const source = cold('-1-2-3----4-#'); + const sourceSubs = '^ !'; + const published = source.publishReplay(1); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3----4-#'; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23----4-#'; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3-4-#'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should multicast the same values to multiple observers, ' + + 'but is unsubscribed explicitly and early', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ ! '; + const published = source.publishReplay(1); + const unsub = ' u '; + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3---- '; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23---- '; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3- '; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + // Set up unsubscription action + let connection; + expectObservable(hot(unsub).do(() => { + connection.unsubscribe(); + })).toBe(unsub); + + connection = published.connect(); + }); + + it('should not break unsubscription chains when result is unsubscribed explicitly', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ ! '; + const published = source + .mergeMap((x: any) => Observable.of(x)) + .publishReplay(1); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3---- '; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23---- '; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3- '; + const unsub = ' u '; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + // Set up unsubscription action + let connection; + expectObservable(hot(unsub).do(() => { + connection.unsubscribe(); + })).toBe(unsub); + + connection = published.connect(); + }); + + describe('with refCount()', () => { + it('should connect when first subscriber subscribes', () => { + const source = cold( '-1-2-3----4-|'); + const sourceSubs = ' ^ !'; + const replayed = source.publishReplay(1).refCount(); + const subscriber1 = hot(' a| ').mergeMapTo(replayed); + const expected1 = ' -1-2-3----4-|'; + const subscriber2 = hot(' b| ').mergeMapTo(replayed); + const expected2 = ' 23----4-|'; + const subscriber3 = hot(' c| ').mergeMapTo(replayed); + const expected3 = ' 3-4-|'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should disconnect when last subscriber unsubscribes', () => { + const source = cold( '-1-2-3----4-|'); + const sourceSubs = ' ^ ! '; + const replayed = source.publishReplay(1).refCount(); + const subscriber1 = hot(' a| ').mergeMapTo(replayed); + const unsub1 = ' ! '; + const expected1 = ' -1-2-3-- '; + const subscriber2 = hot(' b| ').mergeMapTo(replayed); + const unsub2 = ' ! '; + const expected2 = ' 23---- '; + + expectObservable(subscriber1, unsub1).toBe(expected1); + expectObservable(subscriber2, unsub2).toBe(expected2); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should NOT be retryable', () => { + const source = cold('-1-2-3----4-#'); + const sourceSubs = '^ !'; + const published = source.publishReplay(1).refCount().retry(3); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3----4-(444#)'; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23----4-(444#)'; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3-4-(444#)'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + + it('should NOT be repeatable', () => { + const source = cold('-1-2-3----4-|'); + const sourceSubs = '^ !'; + const published = source.publishReplay(1).refCount().repeat(3); + const subscriber1 = hot('a| ').mergeMapTo(published); + const expected1 = '-1-2-3----4-(44|)'; + const subscriber2 = hot(' b| ').mergeMapTo(published); + const expected2 = ' 23----4-(44|)'; + const subscriber3 = hot(' c| ').mergeMapTo(published); + const expected3 = ' 3-4-(44|)'; + + expectObservable(subscriber1).toBe(expected1); + expectObservable(subscriber2).toBe(expected2); + expectObservable(subscriber3).toBe(expected3); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + }); + }); + + it('should multicast one observable to multiple observers', (done: MochaDone) => { + const results1 = []; + const results2 = []; + let subscriptions = 0; + + const source = new Observable((observer: Rx.Observer) => { + subscriptions++; + observer.next(1); + observer.next(2); + observer.next(3); + observer.next(4); + observer.complete(); + }); + + const connectable = source.publishReplay(); + + connectable.subscribe((x: number) => { + results1.push(x); + }); + connectable.subscribe((x: number) => { + results2.push(x); + }); + + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); + + connectable.connect(); + + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results2).to.deep.equal([1, 2, 3, 4]); + expect(subscriptions).to.equal(1); + done(); + }); + + it('should replay as many events as specified by the bufferSize', (done: MochaDone) => { + const results1 = []; + const results2 = []; + let subscriptions = 0; + + const source = new Observable((observer: Rx.Observer) => { + subscriptions++; + observer.next(1); + observer.next(2); + observer.next(3); + observer.next(4); + observer.complete(); + }); + + const connectable = source.publishReplay(2); + + connectable.subscribe((x: number) => { + results1.push(x); + }); + + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); + + connectable.connect(); + + connectable.subscribe((x: number) => { + results2.push(x); + }); + + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results2).to.deep.equal([3, 4]); + expect(subscriptions).to.equal(1); + done(); + }); + + it('should emit replayed values plus completed when subscribed after completed', (done: MochaDone) => { + const results1 = []; + const results2 = []; + let subscriptions = 0; + + const source = new Observable((observer: Rx.Observer) => { + subscriptions++; + observer.next(1); + observer.next(2); + observer.next(3); + observer.next(4); + observer.complete(); + }); + + const connectable = source.publishReplay(2); + + connectable.subscribe((x: number) => { + results1.push(x); + }); + + expect(results1).to.deep.equal([]); + expect(results2).to.deep.equal([]); + + connectable.connect(); + + expect(results1).to.deep.equal([1, 2, 3, 4]); + expect(results2).to.deep.equal([]); + expect(subscriptions).to.equal(1); + + connectable.subscribe((x: number) => { + results2.push(x); + }, (x) => { + done(new Error('should not be called')); + }, () => { + expect(results2).to.deep.equal([3, 4]); + done(); + }); + }); + + it('should multicast an empty source', () => { + const source = cold('|'); + const sourceSubs = '(^!)'; + const published = source.publishReplay(1); + const expected = '|'; + + expectObservable(published).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should multicast a never source', () => { + const source = cold('-'); + const sourceSubs = '^'; + + const published = source.publishReplay(1); + const expected = '-'; + + expectObservable(published).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should multicast a throw source', () => { + const source = cold('#'); + const sourceSubs = '(^!)'; + const published = source.publishReplay(1); + const expected = '#'; + + expectObservable(published).toBe(expected); + expectSubscriptions(source.subscriptions).toBe(sourceSubs); + + published.connect(); + }); + + it('should follow the RxJS 4 behavior and NOT allow you to reconnect by subscribing again', (done: MochaDone) => { + const expected = [1, 2, 3, 4]; + let i = 0; + + const source = Observable.of(1, 2, 3, 4).publishReplay(1); + + const results = []; + + source.subscribe( + (x: number) => { + expect(x).to.equal(expected[i++]); + }, (x) => { + done(new Error('should not be called')); + }, () => { + source.subscribe((x: number) => { + results.push(x); + }, (x) => { + done(new Error('should not be called')); + }, () => { + done(); + }); + + expect(() => source.connect()).to.throw(Rx.ObjectUnsubscribedError); + }); + + source.connect(); + + expect(results).to.deep.equal([4]); + }); }); \ No newline at end of file diff --git a/spec/operators/refCount-spec.ts b/spec/operators/refCount-spec.ts index aeddb45f7b..d069231787 100644 --- a/spec/operators/refCount-spec.ts +++ b/spec/operators/refCount-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {cold, expectObservable, asDiagram, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -28,14 +28,14 @@ describe('ConnectableObservable.prototype.refCount', () => { const sub3 = source.subscribe({ next: function () { //noop } }); - expect((source).refCount).toBe(3); + expect((source).refCount).to.equal(3); sub1.unsubscribe(); sub2.unsubscribe(); sub3.unsubscribe(); }); - it('should unsub from the source when all other subscriptions are unsubbed', (done: DoneSignature) => { + it('should unsub from the source when all other subscriptions are unsubbed', (done: MochaDone) => { let unsubscribeCalled = false; const source = new Observable((observer: Rx.Observer) => { observer.next(true); @@ -52,15 +52,15 @@ describe('ConnectableObservable.prototype.refCount', () => { //noop }); const sub3 = source.subscribe((x: any) => { - expect((source).refCount).toBe(1); + expect((source).refCount).to.equal(1); }); sub1.unsubscribe(); sub2.unsubscribe(); sub3.unsubscribe(); - expect((source).refCount).toBe(0); - expect(unsubscribeCalled).toBe(true); + expect((source).refCount).to.equal(0); + expect(unsubscribeCalled).to.be.true; done(); }); }); \ No newline at end of file diff --git a/spec/operators/repeat-spec.ts b/spec/operators/repeat-spec.ts index f2f36bbc89..e75540fd6b 100644 --- a/spec/operators/repeat-spec.ts +++ b/spec/operators/repeat-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -218,7 +218,7 @@ describe('Observable.prototype.repeat', () => { expect(() => { e1.repeat(3); rxTestScheduler.flush(); - }).toThrow(); + }).to.throw(); }); it('should terminate repeat and throw if source subscription to _complete throws', () => { @@ -232,7 +232,7 @@ describe('Observable.prototype.repeat', () => { expect(() => { e1.repeat(3); rxTestScheduler.flush(); - }).toThrow(); + }).to.throw(); }); it('should terminate repeat and throw if source subscription to _next throws when repeating infinitely', () => { @@ -242,7 +242,7 @@ describe('Observable.prototype.repeat', () => { expect(() => { e1.repeat(); rxTestScheduler.flush(); - }).toThrow(); + }).to.throw(); }); it('should terminate repeat and throw if source subscription to _complete throws when repeating infinitely', () => { @@ -256,7 +256,7 @@ describe('Observable.prototype.repeat', () => { expect(() => { e1.repeat(); rxTestScheduler.flush(); - }).toThrow(); + }).to.throw(); }); it('should raise error after first emit succeed', () => { @@ -275,7 +275,7 @@ describe('Observable.prototype.repeat', () => { expectObservable(e1.repeat(2)).toBe(expected); }); - it('should repeat a synchronous source (multicasted and refCounted) multiple times', (done: DoneSignature) => { + it('should repeat a synchronous source (multicasted and refCounted) multiple times', (done: MochaDone) => { const expected = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]; Observable.of(1, 2, 3) @@ -283,11 +283,11 @@ describe('Observable.prototype.repeat', () => { .refCount() .repeat(5) .subscribe( - (x: number) => { expect(x).toBe(expected.shift()); }, + (x: number) => { expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); diff --git a/spec/operators/retry-spec.ts b/spec/operators/retry-spec.ts index 012bd6dde3..8cbd20943c 100644 --- a/spec/operators/retry-spec.ts +++ b/spec/operators/retry-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -19,7 +19,7 @@ describe('Observable.prototype.retry', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should retry a number of times, without error, then complete', (done: DoneSignature) => { + it('should retry a number of times, without error, then complete', (done: MochaDone) => { let errors = 0; const retries = 2; Observable.create((observer: Rx.Observer) => { @@ -36,14 +36,14 @@ describe('Observable.prototype.retry', () => { .retry(retries) .subscribe( (x: number) => { - expect(x).toBe(42); + expect(x).to.equal(42); }, (err: any) => { - expect('this was called').toBe(false); + expect('this was called').to.be.true; }, done); }); - it('should retry a number of times, then call error handler', (done: DoneSignature) => { + it('should retry a number of times, then call error handler', (done: MochaDone) => { let errors = 0; const retries = 2; Observable.create((observer: Rx.Observer) => { @@ -57,17 +57,17 @@ describe('Observable.prototype.retry', () => { .retry(retries - 1) .subscribe( (x: number) => { - expect(x).toBe(42); + expect(x).to.equal(42); }, (err: any) => { - expect(errors).toBe(2); + expect(errors).to.equal(2); done(); }, () => { - expect('this was called').toBe(false); + expect('this was called').to.be.true; }); }); - it('should retry until successful completion', (done: DoneSignature) => { + it('should retry until successful completion', (done: MochaDone) => { let errors = 0; const retries = 10; Observable.create((observer: Rx.Observer) => { @@ -85,10 +85,10 @@ describe('Observable.prototype.retry', () => { .take(retries) .subscribe( (x: number) => { - expect(x).toBe(42); + expect(x).to.equal(42); }, (err: any) => { - expect('this was called').toBe(false); + expect('this was called').to.be.true; }, done); }); @@ -192,7 +192,7 @@ describe('Observable.prototype.retry', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should retry a synchronous source (multicasted and refCounted) multiple times', (done: DoneSignature) => { + it('should retry a synchronous source (multicasted and refCounted) multiple times', (done: MochaDone) => { const expected = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]; Observable.of(1, 2, 3).concat(Observable.throw('bad!')) @@ -200,13 +200,13 @@ describe('Observable.prototype.retry', () => { .refCount() .retry(4) .subscribe( - (x: number) => { expect(x).toBe(expected.shift()); }, + (x: number) => { expect(x).to.equal(expected.shift()); }, (err: any) => { - expect(err).toBe('bad!'); - expect(expected.length).toBe(0); + expect(err).to.equal('bad!'); + expect(expected.length).to.equal(0); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); }); \ No newline at end of file diff --git a/spec/operators/retryWhen-spec.ts b/spec/operators/retryWhen-spec.ts index d213db07cd..e9ac2ebcd6 100644 --- a/spec/operators/retryWhen-spec.ts +++ b/spec/operators/retryWhen-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -34,7 +34,7 @@ describe('Observable.prototype.retryWhen', () => { expectSubscriptions(source.subscriptions).toBe(subs); }); - it('should retry when notified via returned notifier on thrown error', (done: DoneSignature) => { + it('should retry when notified via returned notifier on thrown error', (done: MochaDone) => { let retried = false; const expected = [1, 2, 1, 2]; let i = 0; @@ -46,23 +46,23 @@ describe('Observable.prototype.retryWhen', () => { return n; }) .retryWhen((errors: any) => errors.map((x: any) => { - expect(x).toBe('bad'); + expect(x).to.equal('bad'); if (retried) { - throw 'done'; + throw new Error('done'); } retried = true; return x; })) .subscribe((x: any) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, (err: any) => { - expect(err).toBe('done'); + expect(err).to.be.an('error', 'done'); done(); }); }); - it('should retry when notified and complete on returned completion', (done: DoneSignature) => { + it('should retry when notified and complete on returned completion', (done: MochaDone) => { const expected = [1, 2, 1, 2]; Observable.of(1, 2, 3) .map((n: number) => { @@ -73,9 +73,9 @@ describe('Observable.prototype.retryWhen', () => { }) .retryWhen((errors: any) => Observable.empty()) .subscribe((n: number) => { - expect(n).toBe(expected.shift()); + expect(n).to.equal(expected.shift()); }, (err: any) => { - done.fail('error should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/operators/share-spec.ts b/spec/operators/share-spec.ts index e8fd53517b..4e3c979d91 100644 --- a/spec/operators/share-spec.ts +++ b/spec/operators/share-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -24,12 +25,12 @@ describe('Observable.prototype.share', () => { const source = obs.share(); - expect(subscriptionCount).toBe(0); + expect(subscriptionCount).to.equal(0); source.subscribe(); source.subscribe(); - expect(subscriptionCount).toBe(1); + expect(subscriptionCount).to.equal(1); }); it('should not change the output of the observable when error', () => { diff --git a/spec/operators/skipWhile-spec.ts b/spec/operators/skipWhile-spec.ts index 63bc3299de..45bc82b3ab 100644 --- a/spec/operators/skipWhile-spec.ts +++ b/spec/operators/skipWhile-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -139,7 +140,7 @@ describe('Observable.prototype.skipWhile', () => { expectObservable( source.skipWhile(predicate).do(null, null, () => { - expect(invoked).toBe(3); + expect(invoked).to.equal(3); }) ).toBe(expected); expectSubscriptions(source.subscriptions).toBe(sourceSubs); diff --git a/spec/operators/switch-spec.ts b/spec/operators/switch-spec.ts index 0e9c900c70..8b3b7427c5 100644 --- a/spec/operators/switch-spec.ts +++ b/spec/operators/switch-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; const queueScheduler = Rx.Scheduler.queue; @@ -16,7 +16,7 @@ describe('Observable.prototype.switch', () => { expectObservable(e1.switch()).toBe(expected); }); - it('should switch to each immediately-scheduled inner Observable', (done: DoneSignature) => { + it('should switch to each immediately-scheduled inner Observable', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, queueScheduler); const r = [1, 4, 5, 6]; @@ -24,7 +24,7 @@ describe('Observable.prototype.switch', () => { Observable.of>(a, b, queueScheduler) .switch() .subscribe((x: number) => { - expect(x).toBe(r[i++]); + expect(x).to.equal(r[i++]); }, null, done); }); @@ -41,16 +41,16 @@ describe('Observable.prototype.switch', () => { .mergeAll() .subscribe(); - expect(unsubbed).toEqual(['a', 'b']); + expect(unsubbed).to.deep.equal(['a', 'b']); }); - it('should switch to each inner Observable', (done: DoneSignature) => { + it('should switch to each inner Observable', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const b = Observable.of(4, 5, 6); const r = [1, 2, 3, 4, 5, 6]; let i = 0; Observable.of(a, b).switch().subscribe((x: number) => { - expect(x).toBe(r[i++]); + expect(x).to.equal(r[i++]); }, null, done); }); @@ -176,29 +176,29 @@ describe('Observable.prototype.switch', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should handle an observable of promises', (done: DoneSignature) => { + it('should handle an observable of promises', (done: MochaDone) => { const expected = [3]; (Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3))) .switch() .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); }); }); - it('should handle an observable of promises, where last rejects', (done: DoneSignature) => { + it('should handle an observable of promises, where last rejects', (done: MochaDone) => { Observable.of(Promise.resolve(1), Promise.resolve(2), Promise.reject(3)) .switch() .subscribe(() => { - done.fail(); + done(new Error('should not be called')); }, (err: any) => { - expect(err).toBe(3); + expect(err).to.equal(3); done(); }, () => { - done.fail(); + done(new Error('should not be called')); }); }); @@ -209,12 +209,12 @@ describe('Observable.prototype.switch', () => { Observable.of(Observable.never(), Observable.never(), [1, 2, 3, 4]) .switch() .subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { completed = true; - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); }); - expect(completed).toBe(true); + expect(completed).to.be.true; }); }); \ No newline at end of file diff --git a/spec/operators/switchMap-spec.ts b/spec/operators/switchMap-spec.ts index 27b49dbe31..7639c55695 100644 --- a/spec/operators/switchMap-spec.ts +++ b/spec/operators/switchMap-spec.ts @@ -1,17 +1,17 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; /** @test {switchMap} */ describe('Observable.prototype.switchMap', () => { - it('should switch with a selector function', (done: DoneSignature) => { + it('should switch with a selector function', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const expected = ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', 'a3', 'b3', 'c3']; a.switchMap((x: number) => Observable.of('a' + x, 'b' + x, 'c' + x)) .subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, done); }); @@ -26,7 +26,7 @@ describe('Observable.prototype.switchMap', () => { }; })).subscribe(); - expect(unsubbed).toEqual(['a', 'b']); + expect(unsubbed).to.deep.equal(['a', 'b']); }); it('should switch inner cold observables', () => { diff --git a/spec/operators/switchMapTo-spec.ts b/spec/operators/switchMapTo-spec.ts index 7d3cebd15d..62ec04f938 100644 --- a/spec/operators/switchMapTo-spec.ts +++ b/spec/operators/switchMapTo-spec.ts @@ -1,16 +1,16 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; /** @test {switchMapTo} */ describe('Observable.prototype.switchMapTo', () => { - it('should switch a synchronous many outer to a synchronous many inner', (done: DoneSignature) => { + it('should switch a synchronous many outer to a synchronous many inner', (done: MochaDone) => { const a = Observable.of(1, 2, 3); const expected = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']; a.switchMapTo(Observable.of('a', 'b', 'c')).subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, done); }); @@ -26,7 +26,7 @@ describe('Observable.prototype.switchMapTo', () => { }) ).subscribe(); - expect(unsubbed).toEqual(2); + expect(unsubbed).to.equal(2); }); it('should switch to an inner cold observable', () => { diff --git a/spec/operators/take-spec.ts b/spec/operators/take-spec.ts index a34717926b..f106d31b51 100644 --- a/spec/operators/take-spec.ts +++ b/spec/operators/take-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -107,7 +108,7 @@ describe('Observable.prototype.take', () => { it('should throw if total is less than zero', () => { expect(() => { Observable.range(0, 10).take(-1); }) - .toThrow(new Rx.ArgumentOutOfRangeError()); + .to.throw(Rx.ArgumentOutOfRangeError); }); it('should not break unsubscription chain when unsubscribed explicitly', () => { diff --git a/spec/operators/takeLast-spec.ts b/spec/operators/takeLast-spec.ts index 7664b879b0..a98f289a7f 100644 --- a/spec/operators/takeLast-spec.ts +++ b/spec/operators/takeLast-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -141,7 +142,7 @@ describe('Observable.prototype.takeLast', () => { it('should throw if total is less than zero', () => { expect(() => { Observable.range(0, 10).takeLast(-1); }) - .toThrow(new Rx.ArgumentOutOfRangeError()); + .to.throw(Rx.ArgumentOutOfRangeError); }); it('should not break unsubscription chain when unsubscribed explicitly', () => { diff --git a/spec/operators/takeWhile-spec.ts b/spec/operators/takeWhile-spec.ts index 94c7b4d110..69f4c215a8 100644 --- a/spec/operators/takeWhile-spec.ts +++ b/spec/operators/takeWhile-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; @@ -147,7 +148,7 @@ describe('Observable.prototype.takeWhile', () => { } const source = e1.takeWhile(predicate).do(null, null, () => { - expect(invoked).toBe(3); + expect(invoked).to.equal(3); }); expectObservable(source).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); diff --git a/spec/operators/throttle-spec.ts b/spec/operators/throttle-spec.ts index d95fa8584d..2fb85c721f 100644 --- a/spec/operators/throttle-spec.ts +++ b/spec/operators/throttle-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; const Observable = Rx.Observable; @@ -280,7 +280,7 @@ describe('Observable.prototype.throttle', () => { expectSubscriptions(e1.subscriptions).toBe(subs); }); - it('should throttle by promise resolves', (done: DoneSignature) => { + it('should throttle by promise resolves', (done: MochaDone) => { const e1 = Observable.concat(Observable.of(1), Observable.timer(10).mapTo(2), Observable.timer(10).mapTo(3), @@ -292,18 +292,18 @@ describe('Observable.prototype.throttle', () => { return new Promise((resolve: any) => { resolve(42); }); }).subscribe( (x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); done(); } ); }); - it('should raise error when promise rejects', (done: DoneSignature) => { + it('should raise error when promise rejects', (done: MochaDone) => { const e1 = Observable.concat(Observable.of(1), Observable.timer(10).mapTo(2), Observable.timer(10).mapTo(3), @@ -320,14 +320,14 @@ describe('Observable.prototype.throttle', () => { } }).subscribe( (x: number) => { - expect(x).toEqual(expected.shift()); }, + expect(x).to.equal(expected.shift()); }, (err: any) => { - expect(err).toBe(error); - expect(expected.length).toBe(0); + expect(err).to.be.an('error', 'error'); + expect(expected.length).to.equal(0); done(); }, () => { - done.fail('should not be called'); + done(new Error('should not be called')); } ); }); diff --git a/spec/operators/throttleTime-spec.ts b/spec/operators/throttleTime-spec.ts index 17f05abdec..8d4a9f92c2 100644 --- a/spec/operators/throttleTime-spec.ts +++ b/spec/operators/throttleTime-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: Rx.TestScheduler; const Observable = Rx.Observable; @@ -18,10 +18,10 @@ describe('Observable.prototype.throttleTime', () => { expectSubscriptions(e1.subscriptions).toBe(subs); }); - it('should throttle events by 50 time units', (done: DoneSignature) => { + it('should throttle events by 50 time units', (done: MochaDone) => { Observable.of(1, 2, 3).throttleTime(50) .subscribe((x: number) => { - expect(x).toBe(1); + expect(x).to.equal(1); }, null, done); }); @@ -33,7 +33,7 @@ describe('Observable.prototype.throttleTime', () => { ) .throttleTime(50, rxTestScheduler) .subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }); rxTestScheduler.flush(); diff --git a/spec/operators/toPromise-spec.ts b/spec/operators/toPromise-spec.ts index e460193e2b..12dffdb0cb 100644 --- a/spec/operators/toPromise-spec.ts +++ b/spec/operators/toPromise-spec.ts @@ -1,28 +1,28 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; declare const __root__: any; const Observable = Rx.Observable; /** @test {toPromise} */ describe('Observable.prototype.toPromise', () => { - it('should convert an Observable to a promise of its last value', (done: DoneSignature) => { + it('should convert an Observable to a promise of its last value', (done: MochaDone) => { Observable.of(1, 2, 3).toPromise(Promise).then((x: number) => { - expect(x).toBe(3); + expect(x).to.equal(3); done(); }); }); - it('should handle errors properly', (done: DoneSignature) => { + it('should handle errors properly', (done: MochaDone) => { Observable.throw('bad').toPromise(Promise).then(() => { - done.fail('should not be called'); + done(new Error('should not be called')); }, (err: any) => { - expect(err).toBe('bad'); + expect(err).to.equal('bad'); done(); }); }); - it('should allow for global config via Rx.config.Promise', (done: DoneSignature) => { + it('should allow for global config via Rx.config.Promise', (done: MochaDone) => { let wasCalled = false; __root__.Rx = {}; __root__.Rx.config = {}; @@ -32,8 +32,8 @@ describe('Observable.prototype.toPromise', () => { }; Observable.of(42).toPromise().then((x: number) => { - expect(wasCalled).toBe(true); - expect(x).toBe(42); + expect(wasCalled).to.be.true; + expect(x).to.equal(42); done(); }); }); diff --git a/spec/operators/window-spec.ts b/spec/operators/window-spec.ts index 528e2476b3..78aac89226 100644 --- a/spec/operators/window-spec.ts +++ b/spec/operators/window-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, time, expectObservable, expectSubscriptions}; @@ -218,7 +219,7 @@ describe('Observable.prototype.window', () => { rxTestScheduler.schedule(() => { expect(() => { window.subscribe(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }, late); }); diff --git a/spec/operators/windowCount-spec.ts b/spec/operators/windowCount-spec.ts index b38eb47d24..e32786bee1 100644 --- a/spec/operators/windowCount-spec.ts +++ b/spec/operators/windowCount-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, time, expectObservable, expectSubscriptions}; @@ -148,7 +149,7 @@ describe('Observable.prototype.windowCount', () => { rxTestScheduler.schedule(() => { expect(() => { window.subscribe(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }, late); }); diff --git a/spec/operators/windowTime-spec.ts b/spec/operators/windowTime-spec.ts index f68fd58237..2fd9e67e84 100644 --- a/spec/operators/windowTime-spec.ts +++ b/spec/operators/windowTime-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, time, expectObservable, expectSubscriptions}; @@ -188,7 +189,7 @@ describe('Observable.prototype.windowTime', () => { rxTestScheduler.schedule(() => { expect(() => { window.subscribe(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }, 150); }); diff --git a/spec/operators/windowToggle-spec.ts b/spec/operators/windowToggle-spec.ts index f368f6c5e5..85c62aaa1b 100644 --- a/spec/operators/windowToggle-spec.ts +++ b/spec/operators/windowToggle-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, time, expectObservable, expectSubscriptions}; @@ -51,7 +52,7 @@ describe('Observable.prototype.windowToggle', () => { const values = { x: x, y: y, z: z }; const source = e1.windowToggle(e2, (value: string) => { - expect(value).toBe('x'); + expect(value).to.equal('x'); return e3; }); @@ -217,7 +218,7 @@ describe('Observable.prototype.windowToggle', () => { rxTestScheduler.schedule(() => { expect(() => { window.subscribe(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }, late); }); diff --git a/spec/operators/windowWhen-spec.ts b/spec/operators/windowWhen-spec.ts index b5c047adf8..6a2f230b67 100644 --- a/spec/operators/windowWhen-spec.ts +++ b/spec/operators/windowWhen-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, asDiagram, time, expectObservable, expectSubscriptions}; @@ -172,7 +173,7 @@ describe('Observable.prototype.windowWhen', () => { rxTestScheduler.schedule(() => { expect(() => { window.subscribe(); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }, late); }); diff --git a/spec/operators/withLatestFrom-spec.ts b/spec/operators/withLatestFrom-spec.ts index 26266a7dec..79a1c5cbec 100644 --- a/spec/operators/withLatestFrom-spec.ts +++ b/spec/operators/withLatestFrom-spec.ts @@ -1,5 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature, lowerCaseO} from '../helpers/test-helper'; +import {lowerCaseO} from '../helpers/test-helper'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; const Observable = Rx.Observable; @@ -239,24 +240,24 @@ describe('Observable.prototype.withLatestFrom', () => { expectSubscriptions(e3.subscriptions).toBe(e3subs); }); - it('should handle promises', (done: DoneSignature) => { + it('should handle promises', (done: MochaDone) => { Observable.of(1).delay(1).withLatestFrom(Promise.resolve(2), Promise.resolve(3)) .subscribe((x: any) => { - expect(x).toEqual([1, 2, 3]); + expect(x).to.deep.equal([1, 2, 3]); }, null, done); }); it('should handle arrays', () => { Observable.of(1).delay(1).withLatestFrom([2, 3, 4], [4, 5, 6]) .subscribe((x: any) => { - expect(x).toEqual([1, 4, 6]); + expect(x).to.deep.equal([1, 4, 6]); }); }); it('should handle lowercase-o observables', () => { Observable.of(1).delay(1).withLatestFrom(lowerCaseO(2, 3, 4), lowerCaseO(4, 5, 6)) .subscribe((x: any) => { - expect(x).toEqual([1, 4, 6]); + expect(x).to.deep.equal([1, 4, 6]); }); }); }); \ No newline at end of file diff --git a/spec/operators/zip-spec.ts b/spec/operators/zip-spec.ts index d17e883b54..2fc29de552 100644 --- a/spec/operators/zip-spec.ts +++ b/spec/operators/zip-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const Symbol: any; const Observable = Rx.Observable; @@ -21,7 +21,7 @@ describe('Observable.prototype.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should zip the provided observables', (done: DoneSignature) => { + it('should zip the provided observables', (done: MochaDone) => { const expected = ['a1', 'b2', 'c3']; let i = 0; @@ -30,7 +30,7 @@ describe('Observable.prototype.zip', () => { (a: string, b: number): string => a + b ) .subscribe(function (x) { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, null, done); }); @@ -116,7 +116,7 @@ describe('Observable.prototype.zip', () => { // since zip will call `next()` in advance, total calls when // zipped with 3 other values should be 4. - expect(nextCalled).toBe(4); + expect(nextCalled).to.equal(4); }); it('should work with never observable and empty iterable', () => { @@ -562,14 +562,14 @@ describe('Observable.prototype.zip', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: DoneSignature) => { + it('should combine an immediately-scheduled source with an immediately-scheduled second', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 5], [3, 6]]; let i = 0; a.zip(b).subscribe(function (vals) { - (expect(vals)).toDeepEqual(r[i++]); + expect(vals).to.deep.equal(r[i++]); }, null, done); }); diff --git a/spec/operators/zipAll-spec.ts b/spec/operators/zipAll-spec.ts index b634691a9e..a013b30116 100644 --- a/spec/operators/zipAll-spec.ts +++ b/spec/operators/zipAll-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; -import {DoneSignature} from '../helpers/test-helper'; declare const Symbol: any; const Observable = Rx.Observable; @@ -32,7 +32,7 @@ describe('Observable.prototype.zipAll', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should take all observables from the source and zip them', (done: DoneSignature) => { + it('should take all observables from the source and zip them', (done: MochaDone) => { const expected = ['a1', 'b2', 'c3']; let i = 0; Observable.of( @@ -41,7 +41,7 @@ describe('Observable.prototype.zipAll', () => { ) .zipAll((a: any, b: any) => a + b) .subscribe((x: any) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, null, done); }); @@ -127,7 +127,7 @@ describe('Observable.prototype.zipAll', () => { // since zip will call `next()` in advance, total calls when // zipped with 3 other values should be 4. - expect(nextCalled).toBe(4); + expect(nextCalled).to.equal(4); }); it('should work with never observable and empty iterable', () => { @@ -367,7 +367,7 @@ describe('Observable.prototype.zipAll', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should zip until one child terminates', (done: DoneSignature) => { + it('should zip until one child terminates', (done: MochaDone) => { const expected = ['a1', 'b2']; let i = 0; Observable.of( @@ -376,7 +376,7 @@ describe('Observable.prototype.zipAll', () => { ) .zipAll((a: any, b: any) => a + b) .subscribe((x: any) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, null, done); }); @@ -673,7 +673,7 @@ describe('Observable.prototype.zipAll', () => { expectSubscriptions(b.subscriptions).toBe(bsubs); }); - it('should combine two immediately-scheduled observables', (done: DoneSignature) => { + it('should combine two immediately-scheduled observables', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8, queueScheduler); const r = [[1, 4], [2, 5], [3, 6]]; @@ -682,11 +682,11 @@ describe('Observable.prototype.zipAll', () => { const result = Observable.of(a, b, queueScheduler).zipAll(); result.subscribe((vals: any) => { - (expect(vals)).toDeepEqual(r[i++]); + expect(vals).to.deep.equal(r[i++]); }, null, done); }); - it('should combine a source with an immediately-scheduled source', (done: DoneSignature) => { + it('should combine a source with an immediately-scheduled source', (done: MochaDone) => { const a = Observable.of(1, 2, 3, queueScheduler); const b = Observable.of(4, 5, 6, 7, 8); const r = [[1, 4], [2, 5], [3, 6]]; @@ -695,7 +695,7 @@ describe('Observable.prototype.zipAll', () => { const result = Observable.of(a, b, queueScheduler).zipAll(); result.subscribe((vals: any) => { - (expect(vals)).toDeepEqual(r[i++]); + expect(vals).to.deep.equal(r[i++]); }, null, done); }); diff --git a/spec/root-module-spec.ts b/spec/root-module-spec.ts index 0685301582..e59b013d7f 100644 --- a/spec/root-module-spec.ts +++ b/spec/root-module-spec.ts @@ -1,7 +1,8 @@ +import {expect} from 'chai'; import * as Rx from '../dist/cjs/Rx'; describe('Root Module', () => { it('should contain exports from commonjs modules', () => { - expect(typeof Rx.Observable).toBe('function'); + expect(Rx.Observable).to.be.a('function'); }); }); diff --git a/spec/schedulers/AsapScheduler-spec.ts b/spec/schedulers/AsapScheduler-spec.ts index d6be0f2bf5..20c9e83b31 100644 --- a/spec/schedulers/AsapScheduler-spec.ts +++ b/spec/schedulers/AsapScheduler-spec.ts @@ -1,26 +1,26 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; -import {DoneSignature} from '../helpers/test-helper'; const asap = Rx.Scheduler.asap; /** @test {AsapScheduler} */ describe('AsapScheduler', () => { it('should exist', () => { - expect(asap).toBeDefined(); + expect(asap).exist; }); - it('should schedule an action to happen later', (done: DoneSignature) => { + it('should schedule an action to happen later', (done: MochaDone) => { let actionHappened = false; asap.schedule(() => { actionHappened = true; done(); }); if (actionHappened) { - done.fail('Scheduled action happened synchronously'); + done(new Error('Scheduled action happened synchronously')); } }); - it('should execute the rest of the scheduled actions if the first action is canceled', (done: DoneSignature) => { + it('should execute the rest of the scheduled actions if the first action is canceled', (done: MochaDone) => { let actionHappened = false; let firstSubscription = null; let secondSubscription = null; @@ -30,7 +30,7 @@ describe('AsapScheduler', () => { if (secondSubscription) { secondSubscription.unsubscribe(); } - done.fail('The first action should not have executed.'); + done(new Error('The first action should not have executed.')); }); secondSubscription = asap.schedule(() => { @@ -40,7 +40,7 @@ describe('AsapScheduler', () => { }); if (actionHappened) { - done.fail('Scheduled action happened synchronously'); + done(new Error('Scheduled action happened synchronously')); } else { firstSubscription.unsubscribe(); } diff --git a/spec/schedulers/TestScheduler-spec.ts b/spec/schedulers/TestScheduler-spec.ts index b15801eb4a..4cbac8b683 100644 --- a/spec/schedulers/TestScheduler-spec.ts +++ b/spec/schedulers/TestScheduler-spec.ts @@ -1,4 +1,4 @@ -/* globals describe, it, expect, expectObservable, expectSubscriptions, rxTestScheduler, hot, cold */ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; declare const {hot, cold, time, expectObservable, expectSubscriptions}; @@ -9,14 +9,14 @@ const TestScheduler = Rx.TestScheduler; /** @test {TestScheduler} */ describe('TestScheduler', () => { it('should exist', () => { - expect(TestScheduler).toBeDefined(); - expect(typeof TestScheduler).toBe('function'); + expect(TestScheduler).exist; + expect(TestScheduler).to.be.a('function'); }); describe('parseMarbles()', () => { it('should parse a marble string into a series of notifications and types', () => { const result = TestScheduler.parseMarbles('-------a---b---|', { a: 'A', b: 'B' }); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 70, notification: Notification.createNext('A') }, { frame: 110, notification: Notification.createNext('B') }, { frame: 150, notification: Notification.createComplete() } @@ -25,7 +25,7 @@ describe('TestScheduler', () => { it('should parse a marble string, allowing spaces too', () => { const result = TestScheduler.parseMarbles('--a--b--| ', { a: 'A', b: 'B' }); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 20, notification: Notification.createNext('A') }, { frame: 50, notification: Notification.createNext('B') }, { frame: 80, notification: Notification.createComplete() } @@ -34,7 +34,7 @@ describe('TestScheduler', () => { it('should parse a marble string with a subscription point', () => { const result = TestScheduler.parseMarbles('---^---a---b---|', { a: 'A', b: 'B' }); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 40, notification: Notification.createNext('A') }, { frame: 80, notification: Notification.createNext('B') }, { frame: 120, notification: Notification.createComplete() } @@ -43,7 +43,7 @@ describe('TestScheduler', () => { it('should parse a marble string with an error', () => { const result = TestScheduler.parseMarbles('-------a---b---#', { a: 'A', b: 'B' }, 'omg error!'); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 70, notification: Notification.createNext('A') }, { frame: 110, notification: Notification.createNext('B') }, { frame: 150, notification: Notification.createError('omg error!') } @@ -52,7 +52,7 @@ describe('TestScheduler', () => { it('should default in the letter for the value if no value hash was passed', () => { const result = TestScheduler.parseMarbles('--a--b--c--'); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 20, notification: Notification.createNext('a') }, { frame: 50, notification: Notification.createNext('b') }, { frame: 80, notification: Notification.createNext('c') }, @@ -61,7 +61,7 @@ describe('TestScheduler', () => { it('should handle grouped values', () => { const result = TestScheduler.parseMarbles('---(abc)---'); - (expect(result)).toDeepEqual([ + expect(result).deep.equal([ { frame: 30, notification: Notification.createNext('a') }, { frame: 30, notification: Notification.createNext('b') }, { frame: 30, notification: Notification.createNext('c') } @@ -72,20 +72,20 @@ describe('TestScheduler', () => { describe('parseMarblesAsSubscriptions()', () => { it('should parse a subscription marble string into a subscriptionLog', () => { const result = TestScheduler.parseMarblesAsSubscriptions('---^---!-'); - expect(result.subscribedFrame).toEqual(30); - expect(result.unsubscribedFrame).toEqual(70); + expect(result.subscribedFrame).to.equal(30); + expect(result.unsubscribedFrame).to.equal(70); }); it('should parse a subscription marble string with an unsubscription', () => { const result = TestScheduler.parseMarblesAsSubscriptions('---^-'); - expect(result.subscribedFrame).toEqual(30); - expect(result.unsubscribedFrame).toEqual(Number.POSITIVE_INFINITY); + expect(result.subscribedFrame).to.equal(30); + expect(result.unsubscribedFrame).to.equal(Number.POSITIVE_INFINITY); }); it('should parse a subscription marble string with a synchronous unsubscription', () => { const result = TestScheduler.parseMarblesAsSubscriptions('---(^!)-'); - expect(result.subscribedFrame).toEqual(30); - expect(result.unsubscribedFrame).toEqual(30); + expect(result.subscribedFrame).to.equal(30); + expect(result.unsubscribedFrame).to.equal(30); }); }); @@ -93,14 +93,14 @@ describe('TestScheduler', () => { it('should parse a simple time marble string to a number', () => { const scheduler = new TestScheduler(null); const time = scheduler.createTime('-----|'); - expect(time).toBe(50); + expect(time).to.equal(50); }); it('should throw if not given good marble input', () => { const scheduler = new TestScheduler(null); expect(() => { scheduler.createTime('-a-b-#'); - }).toThrow(); + }).to.throw(); }); }); @@ -109,12 +109,12 @@ describe('TestScheduler', () => { const expected = ['A', 'B']; const scheduler = new TestScheduler(null); const source = scheduler.createColdObservable('--a---b--|', { a: 'A', b: 'B' }); - expect(source instanceof Rx.Observable).toBe(true); + expect(source instanceof Rx.Observable).to.be.true; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }); scheduler.flush(); - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); }); }); @@ -123,35 +123,35 @@ describe('TestScheduler', () => { const expected = ['A', 'B']; const scheduler = new TestScheduler(null); const source = scheduler.createHotObservable('--a---b--|', { a: 'A', b: 'B' }); - expect(source instanceof Rx.Subject).toBe(true); + expect(source instanceof Rx.Subject).to.be.true; source.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }); scheduler.flush(); - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); }); }); describe('jasmine helpers', () => { describe('rxTestScheduler', () => { it('should exist', () => { - expect(rxTestScheduler instanceof TestScheduler).toBe(true); + expect(rxTestScheduler instanceof TestScheduler).to.be.true; }); }); describe('cold()', () => { it('should exist', () => { - expect(cold).toBeDefined(); - expect(typeof cold).toBe('function'); + expect(cold).to.exist; + expect(cold).to.be.a('function'); }); it('should create a cold observable', () => { const expected = [1, 2]; const source = cold('-a-b-|', { a: 1, b: 2 }); source.subscribe((x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, () => { - expect(expected.length).toBe(0); + expect(expected.length).to.equal(0); }); expectObservable(source).toBe('-a-b-|', { a: 1, b: 2 }); }); @@ -159,41 +159,41 @@ describe('TestScheduler', () => { describe('hot()', () => { it('should exist', () => { - expect(hot).toBeDefined(); - expect(typeof hot).toBe('function'); + expect(hot).to.exist; + expect(hot).to.be.a('function'); }); it('should create a hot observable', () => { const source = hot('---^-a-b-|', { a: 1, b: 2 }); - expect(source instanceof Rx.Subject).toBe(true); + expect(source instanceof Rx.Subject).to.be.true; expectObservable(source).toBe('--a-b-|', { a: 1, b: 2 }); }); }); describe('time()', () => { it('should exist', () => { - expect(time).toBeDefined(); - expect(typeof time).toBe('function'); + expect(time).to.exist; + expect(time).to.be.a('function'); }); it('should parse a simple time marble string to a number', () => { - expect(time('-----|')).toBe(50); + expect(time('-----|')).to.equal(50); }); }); describe('expectObservable()', () => { it('should exist', () => { - expect(expectObservable).toBeDefined(); - expect(typeof expectObservable).toBe('function'); + expect(expectObservable).to.exist; + expect(expectObservable).to.be.a('function'); }); it('should return an object with a toBe function', () => { - expect(typeof (expectObservable(Rx.Observable.of(1)).toBe)).toBe('function'); + expect(expectObservable(Rx.Observable.of(1)).toBe).to.be.a('function'); }); it('should append to flushTests array', () => { expectObservable(Rx.Observable.empty()); - expect((rxTestScheduler).flushTests.length).toBe(1); + expect((rxTestScheduler).flushTests.length).to.equal(1); }); it('should handle empty', () => { @@ -215,17 +215,17 @@ describe('TestScheduler', () => { describe('expectSubscriptions()', () => { it('should exist', () => { - expect(expectSubscriptions).toBeDefined(); - expect(typeof expectSubscriptions).toBe('function'); + expect(expectSubscriptions).to.exist; + expect(expectSubscriptions).to.be.a('function'); }); it('should return an object with a toBe function', () => { - expect(typeof (expectSubscriptions([]).toBe)).toBe('function'); + expect(expectSubscriptions([]).toBe).to.be.a('function'); }); it('should append to flushTests array', () => { expectSubscriptions([]); - expect((rxTestScheduler).flushTests.length).toBe(1); + expect((rxTestScheduler).flushTests.length).to.equal(1); }); it('should assert subscriptions of a cold observable', () => { diff --git a/spec/schedulers/VirtualTimeScheduler-spec.ts b/spec/schedulers/VirtualTimeScheduler-spec.ts index 92f08b66fd..75545e8625 100644 --- a/spec/schedulers/VirtualTimeScheduler-spec.ts +++ b/spec/schedulers/VirtualTimeScheduler-spec.ts @@ -1,4 +1,4 @@ -/* globals describe, it, expect */ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx.KitchenSink'; const VirtualTimeScheduler = Rx.VirtualTimeScheduler; @@ -6,8 +6,8 @@ const VirtualTimeScheduler = Rx.VirtualTimeScheduler; /** @test {VirtualTimeScheduler} */ describe('VirtualTimeScheduler', () => { it('should exist', () => { - expect(VirtualTimeScheduler).toBeDefined(); - expect(typeof VirtualTimeScheduler).toBe('function'); + expect(VirtualTimeScheduler).exist; + expect(VirtualTimeScheduler).to.be.a('function'); }); it('should schedule things in order when flushed if each this is scheduled synchrously', () => { @@ -24,7 +24,7 @@ describe('VirtualTimeScheduler', () => { v.flush(); - expect(invoked).toEqual([1, 2, 3, 4, 5]); + expect(invoked).to.deep.equal([1, 2, 3, 4, 5]); }); it('should schedule things in order when flushed if each this is scheduled at random', () => { @@ -42,7 +42,7 @@ describe('VirtualTimeScheduler', () => { v.flush(); - expect(invoked).toEqual([1, 3, 5, 2, 6, 4]); + expect(invoked).to.deep.equal([1, 3, 5, 2, 6, 4]); }); it('should schedule things in order when there are negative delays', () => { @@ -60,7 +60,7 @@ describe('VirtualTimeScheduler', () => { v.flush(); - expect(invoked).toEqual([6, 4, 1, 3, 5, 2]); + expect(invoked).to.deep.equal([6, 4, 1, 3, 5, 2]); }); it('should support recursive scheduling', () => { @@ -72,11 +72,11 @@ describe('VirtualTimeScheduler', () => { if (++count === 3) { return; } - expect(this.delay).toBe(expected.shift()); + expect(this.delay).to.equal(expected.shift()); this.schedule(state, this.delay); }, 100, 'test'); v.flush(); - expect(count).toBe(3); + expect(count).to.equal(3); }); }); \ No newline at end of file diff --git a/spec/subjects/AsyncSubject-spec.ts b/spec/subjects/AsyncSubject-spec.ts index 2a382c6e1f..3710fb8c7d 100644 --- a/spec/subjects/AsyncSubject-spec.ts +++ b/spec/subjects/AsyncSubject-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; const AsyncSubject = Rx.AsyncSubject; @@ -26,11 +27,11 @@ describe('AsyncSubject', () => { subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.next(2); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual([2, 'done']); + expect(observer.results).to.deep.equal([2, 'done']); }); it('should emit the last value when subscribing after complete', () => { @@ -42,7 +43,7 @@ describe('AsyncSubject', () => { subject.complete(); subject.subscribe(observer); - expect(observer.results).toEqual([2, 'done']); + expect(observer.results).to.deep.equal([2, 'done']); }); it('should keep emitting the last value to subsequent subscriptions', () => { @@ -51,17 +52,17 @@ describe('AsyncSubject', () => { const subscription = subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.next(2); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual([2, 'done']); + expect(observer.results).to.deep.equal([2, 'done']); subscription.unsubscribe(); observer.results = []; subject.subscribe(observer); - expect(observer.results).toEqual([2, 'done']); + expect(observer.results).to.deep.equal([2, 'done']); }); it('should not emit values after complete', () => { @@ -71,11 +72,11 @@ describe('AsyncSubject', () => { subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.next(2); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual([2, 'done']); + expect(observer.results).to.deep.equal([2, 'done']); }); it('should not emit values if unsubscribed before complete', () => { @@ -84,16 +85,16 @@ describe('AsyncSubject', () => { const subscription = subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.next(2); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subscription.unsubscribe(); subject.next(3); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); }); it('should just complete if no value has been nexted into it', () => { @@ -101,9 +102,9 @@ describe('AsyncSubject', () => { const observer = new TestObserver(); subject.subscribe(observer); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual(['done']); + expect(observer.results).to.deep.equal(['done']); }); it('should keep emitting complete to subsequent subscriptions', () => { @@ -111,14 +112,14 @@ describe('AsyncSubject', () => { const observer = new TestObserver(); const subscription = subject.subscribe(observer); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.complete(); - expect(observer.results).toEqual(['done']); + expect(observer.results).to.deep.equal(['done']); subscription.unsubscribe(); observer.results = []; subject.subscribe(observer); - expect(observer.results).toEqual(['done']); + expect(observer.results).to.deep.equal(['done']); }); it('should only error if an error is passed into it', () => { @@ -127,9 +128,9 @@ describe('AsyncSubject', () => { subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.error(new Error('bad')); - expect(observer.results).toEqual([new Error('bad')]); + expect(observer.results).to.deep.equal([new Error('bad')]); }); it('should keep emitting error to subsequent subscriptions', () => { @@ -138,15 +139,15 @@ describe('AsyncSubject', () => { subject.subscribe(observer); subject.next(1); - expect(observer.results).toEqual([]); + expect(observer.results).to.deep.equal([]); subject.error(new Error('bad')); - expect(observer.results).toEqual([new Error('bad')]); + expect(observer.results).to.deep.equal([new Error('bad')]); subject.unsubscribe(); observer.results = []; subject.subscribe(observer); - expect(observer.results).toEqual([new Error('bad')]); + expect(observer.results).to.deep.equal([new Error('bad')]); }); }); diff --git a/spec/subjects/BehaviorSubject-spec.ts b/spec/subjects/BehaviorSubject-spec.ts index c35e9fbad1..cf805749e4 100644 --- a/spec/subjects/BehaviorSubject-spec.ts +++ b/spec/subjects/BehaviorSubject-spec.ts @@ -1,6 +1,6 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, expectObservable}; -import {DoneSignature} from '../helpers/test-helper'; const BehaviorSubject = Rx.BehaviorSubject; const Observable = Rx.Observable; @@ -8,9 +8,9 @@ const ObjectUnsubscribedError = Rx.ObjectUnsubscribedError; /** @test {BehaviorSubject} */ describe('BehaviorSubject', () => { - it('should extend Subject', (done: DoneSignature) => { + it('should extend Subject', (done: MochaDone) => { const subject = new BehaviorSubject(null); - expect(subject instanceof Rx.Subject).toBe(true); + expect(subject instanceof Rx.Subject).to.be.true; done(); }); @@ -19,7 +19,7 @@ describe('BehaviorSubject', () => { subject.error(new Error('derp')); expect(() => { subject.getValue(); - }).toThrow(new Error('derp')); + }).to.throw(Error, 'derp'); }); it('should throw an ObjectUnsubscribedError if getValue() is called ' + @@ -28,16 +28,16 @@ describe('BehaviorSubject', () => { subject.unsubscribe(); expect(() => { subject.getValue(); - }).toThrow(new ObjectUnsubscribedError()); + }).to.throw(ObjectUnsubscribedError); }); it('should have a getValue() method to retrieve the current value', () => { const subject = new BehaviorSubject('staltz'); - expect(subject.getValue()).toBe('staltz'); + expect(subject.getValue()).to.equal('staltz'); subject.next('oj'); - expect(subject.getValue()).toBe('oj'); + expect(subject.getValue()).to.equal('oj'); }); it('should not allow you to set `value` directly', () => { @@ -49,56 +49,56 @@ describe('BehaviorSubject', () => { //noop } - expect(subject.getValue()).toBe('flibberty'); - expect(subject.value).toBe('flibberty'); + expect(subject.getValue()).to.equal('flibberty'); + expect(subject.value).to.equal('flibberty'); }); it('should still allow you to retrieve the value from the value property', () => { const subject = new BehaviorSubject('fuzzy'); - expect(subject.value).toBe('fuzzy'); + expect(subject.value).to.equal('fuzzy'); subject.next('bunny'); - expect(subject.value).toBe('bunny'); + expect(subject.value).to.equal('bunny'); }); - it('should start with an initialization value', (done: DoneSignature) => { + it('should start with an initialization value', (done: MochaDone) => { const subject = new BehaviorSubject('foo'); const expected = ['foo', 'bar']; let i = 0; subject.subscribe((x: string) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }, null, done); subject.next('bar'); subject.complete(); }); - it('should pump values to multiple subscribers', (done: DoneSignature) => { + it('should pump values to multiple subscribers', (done: MochaDone) => { const subject = new BehaviorSubject('init'); const expected = ['init', 'foo', 'bar']; let i = 0; let j = 0; subject.subscribe((x: string) => { - expect(x).toBe(expected[i++]); + expect(x).to.equal(expected[i++]); }); subject.subscribe((x: string) => { - expect(x).toBe(expected[j++]); + expect(x).to.equal(expected[j++]); }, null, done); - expect(subject.observers.length).toBe(2); + expect(subject.observers.length).to.equal(2); subject.next('foo'); subject.next('bar'); subject.complete(); }); - it('should not allow values to be nexted after a return', (done: DoneSignature) => { + it('should not allow values to be nexted after a return', (done: MochaDone) => { const subject = new BehaviorSubject('init'); const expected = ['init', 'foo']; subject.subscribe((x: string) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, null, done); subject.next('foo'); @@ -106,25 +106,25 @@ describe('BehaviorSubject', () => { expect(() => { subject.next('bar'); - }).toThrow(new Rx.ObjectUnsubscribedError()); + }).to.throw(Rx.ObjectUnsubscribedError); }); - it('should clean out unsubscribed subscribers', (done: DoneSignature) => { + it('should clean out unsubscribed subscribers', (done: MochaDone) => { const subject = new BehaviorSubject('init'); const sub1 = subject.subscribe((x: string) => { - expect(x).toBe('init'); + expect(x).to.equal('init'); }); const sub2 = subject.subscribe((x: string) => { - expect(x).toBe('init'); + expect(x).to.equal('init'); }); - expect(subject.observers.length).toBe(2); + expect(subject.observers.length).to.equal(2); sub1.unsubscribe(); - expect(subject.observers.length).toBe(1); + expect(subject.observers.length).to.equal(1); sub2.unsubscribe(); - expect(subject.observers.length).toBe(0); + expect(subject.observers.length).to.equal(0); done(); }); @@ -168,16 +168,16 @@ describe('BehaviorSubject', () => { expectObservable(subscriber1).toBe(expected1); }); - it('should be an Observer which can be given to Observable.subscribe', (done: DoneSignature) => { + it('should be an Observer which can be given to Observable.subscribe', (done: MochaDone) => { const source = Observable.of(1, 2, 3, 4, 5); const subject = new BehaviorSubject(0); const expected = [0, 1, 2, 3, 4, 5]; subject.subscribe( (x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, (x) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); diff --git a/spec/subjects/ReplaySubject-spec.ts b/spec/subjects/ReplaySubject-spec.ts index 2bda1db03f..3dd45cfd5a 100644 --- a/spec/subjects/ReplaySubject-spec.ts +++ b/spec/subjects/ReplaySubject-spec.ts @@ -1,7 +1,7 @@ +import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; import {TestScheduler} from '../../dist/cjs/testing/TestScheduler'; declare const {hot, expectObservable}; -import {DoneSignature} from '../helpers/test-helper'; declare const rxTestScheduler: TestScheduler; @@ -10,13 +10,13 @@ const Observable = Rx.Observable; /** @test {ReplaySubject} */ describe('ReplaySubject', () => { - it('should extend Subject', (done: DoneSignature) => { + it('should extend Subject', (done: MochaDone) => { const subject = new ReplaySubject(); - expect(subject instanceof Rx.Subject).toBe(true); + expect(subject instanceof Rx.Subject).to.be.true; done(); }); - it('should replay values upon subscription', (done: DoneSignature) => { + it('should replay values upon subscription', (done: MochaDone) => { const subject = new ReplaySubject(); const expects = [1, 2, 3]; let i = 0; @@ -24,18 +24,18 @@ describe('ReplaySubject', () => { subject.next(2); subject.next(3); subject.subscribe((x: number) => { - expect(x).toBe(expects[i++]); + expect(x).to.equal(expects[i++]); if (i === 3) { subject.complete(); } }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); }); - it('should replay values and complete', (done: DoneSignature) => { + it('should replay values and complete', (done: MochaDone) => { const subject = new ReplaySubject(); const expects = [1, 2, 3]; let i = 0; @@ -44,11 +44,11 @@ describe('ReplaySubject', () => { subject.next(3); subject.complete(); subject.subscribe((x: number) => { - expect(x).toBe(expects[i++]); + expect(x).to.equal(expects[i++]); }, null, done); }); - it('should replay values and error', (done: DoneSignature) => { + it('should replay values and error', (done: MochaDone) => { const subject = new ReplaySubject(); const expects = [1, 2, 3]; let i = 0; @@ -57,14 +57,14 @@ describe('ReplaySubject', () => { subject.next(3); subject.error('fooey'); subject.subscribe((x: number) => { - expect(x).toBe(expects[i++]); + expect(x).to.equal(expects[i++]); }, (err: any) => { - expect(err).toBe('fooey'); + expect(err).to.equal('fooey'); done(); }); }); - it('should only replay values within its buffer size', (done: DoneSignature) => { + it('should only replay values within its buffer size', (done: MochaDone) => { const subject = new ReplaySubject(2); const expects = [2, 3]; let i = 0; @@ -72,12 +72,12 @@ describe('ReplaySubject', () => { subject.next(2); subject.next(3); subject.subscribe((x: number) => { - expect(x).toBe(expects[i++]); + expect(x).to.equal(expects[i++]); if (i === 2) { subject.complete(); } }, (err: any) => { - done.fail('should not be called'); + done(new Error('should not be called')); }, () => { done(); }); @@ -172,9 +172,9 @@ describe('ReplaySubject', () => { subscription3.unsubscribe(); - expect(results1).toEqual([3, 4, 5, 6, 7]); - expect(results2).toEqual([4, 5, 6, 7, 8]); - expect(results3).toEqual([9, 10, 11]); + expect(results1).to.deep.equal([3, 4, 5, 6, 7]); + expect(results2).to.deep.equal([4, 5, 6, 7, 8]); + expect(results3).to.deep.equal([9, 10, 11]); subject.complete(); }); @@ -222,7 +222,7 @@ describe('ReplaySubject', () => { }); }); - it('should be an Observer which can be given to Observable.subscribe', (done: DoneSignature) => { + it('should be an Observer which can be given to Observable.subscribe', (done: MochaDone) => { const source = Observable.of(1, 2, 3, 4, 5); const subject = new ReplaySubject(3); const expected = [3, 4, 5]; @@ -231,9 +231,9 @@ describe('ReplaySubject', () => { subject.subscribe( (x: number) => { - expect(x).toBe(expected.shift()); + expect(x).to.equal(expected.shift()); }, () => { - done.fail(); + done(new Error()); }, () => { done(); } diff --git a/spec/symbol/iterator-spec.ts b/spec/symbol/iterator-spec.ts index b0f03d3c0a..df52724691 100644 --- a/spec/symbol/iterator-spec.ts +++ b/spec/symbol/iterator-spec.ts @@ -1,3 +1,5 @@ +import {expect} from 'chai'; + import {root} from '../../dist/cjs/util/root'; import {$$iterator} from '../../dist/cjs/symbol/iterator'; @@ -6,25 +8,25 @@ describe('rxSubscriber symbol', () => { const Symbol = root.Symbol; if (typeof Symbol === 'function') { if (Symbol.iterator) { - expect($$iterator).toBe(Symbol.iterator); + expect($$iterator).to.equal(Symbol.iterator); } else if (root.Set && typeof (new root.Set()['@@iterator']) === 'function') { // FF bug coverage - expect($$iterator).toBe('@@iterator'); + expect($$iterator).to.equal('@@iterator'); } else if (root.Map) { // es6-shim specific logic let keys = Object.getOwnPropertyNames(root.Map.prototype); for (let i = 0; i < keys.length; ++i) { let key = keys[i]; if (key !== 'entries' && key !== 'size' && root.Map.prototype[key] === root.Map.prototype['entries']) { - expect($$iterator).toBe(key); + expect($$iterator).to.equal(key); break; } } } else if (typeof Symbol.for === 'function') { - expect($$iterator).toBe(Symbol.for('iterator')); + expect($$iterator).to.equal(Symbol.for('iterator')); } } else { - expect($$iterator).toBe('@@iterator'); + expect($$iterator).to.equal('@@iterator'); } }); }); \ No newline at end of file diff --git a/spec/symbol/observable-spec.ts b/spec/symbol/observable-spec.ts index afc49f3e89..742ed8cc12 100644 --- a/spec/symbol/observable-spec.ts +++ b/spec/symbol/observable-spec.ts @@ -1,3 +1,4 @@ +import {expect} from 'chai'; import {root} from '../../dist/cjs/util/root'; import {$$observable} from '../../dist/cjs/symbol/observable'; @@ -5,10 +6,10 @@ describe('rxSubscriber symbol', () => { it('should exist in the proper form', () => { const Symbol = root.Symbol; if (typeof Symbol === 'function') { - expect(Symbol.observable).toBeDefined(); - expect($$observable).toBe(Symbol.observable); + expect(Symbol.observable).exist; + expect($$observable).to.equal(Symbol.observable); } else { - expect($$observable).toBe('@@observable'); + expect($$observable).to.equal('@@observable'); } }); }); \ No newline at end of file diff --git a/spec/symbol/rxSubscriber-spec.ts b/spec/symbol/rxSubscriber-spec.ts index 26d30e4a48..556bb61763 100644 --- a/spec/symbol/rxSubscriber-spec.ts +++ b/spec/symbol/rxSubscriber-spec.ts @@ -1,12 +1,13 @@ +import {expect} from 'chai'; import {root} from '../../dist/cjs/util/root'; import {$$rxSubscriber} from '../../dist/cjs/symbol/rxSubscriber'; describe('rxSubscriber symbol', () => { it('should exist in the proper form', () => { if (root.Symbol && root.Symbol.for) { - expect($$rxSubscriber).toEqual(root.Symbol.for('rxSubscriber')); + expect($$rxSubscriber).to.equal(root.Symbol.for('rxSubscriber')); } else { - expect($$rxSubscriber).toEqual('@@rxSubscriber'); + expect($$rxSubscriber).to.equal('@@rxSubscriber'); } }); }); \ No newline at end of file diff --git a/spec/util/FastMap-spec.ts b/spec/util/FastMap-spec.ts index 5942bed260..2ae9b2c505 100644 --- a/spec/util/FastMap-spec.ts +++ b/spec/util/FastMap-spec.ts @@ -1,9 +1,10 @@ +import {expect} from 'chai'; import {FastMap} from '../../dist/cjs/util/FastMap'; /** @test {FastMap} */ describe('FastMap', () => { it('should exist', () => { - expect(typeof FastMap).toBe('function'); + expect(FastMap).to.be.a('function'); }); it('should accept string as keys', () => { @@ -14,8 +15,8 @@ describe('FastMap', () => { map.set(key1, 'yo'); map.set(key2, 'what up'); - expect(map.get(key1)).toBe('yo'); - expect(map.get(key2)).toBe('what up'); + expect(map.get(key1)).to.equal('yo'); + expect(map.get(key2)).to.equal('what up'); }); it('should allow setting keys twice', () => { @@ -25,7 +26,7 @@ describe('FastMap', () => { map.set(key1, 'sing'); map.set(key1, 'yodel'); - expect(map.get(key1)).toBe('yodel'); + expect(map.get(key1)).to.equal('yodel'); }); it('should have a delete method that removes keys', () => { @@ -34,8 +35,8 @@ describe('FastMap', () => { map.set(key1, 'sing'); - expect(map.delete(key1)).toBe(true); - expect(map.get(key1)).toBe(null); + expect(map.delete(key1)).to.be.true; + expect(map.get(key1)).to.be.a('null'); }); it('should clear all', () => { @@ -48,14 +49,14 @@ describe('FastMap', () => { map.clear(); - expect(map.get(key1)).toBe(undefined); - expect(map.get(key2)).toBe(undefined); + expect(map.get(key1)).to.be.a('undefined'); + expect(map.get(key2)).to.be.a('undefined'); }); describe('prototype.forEach', () => { it('should exist', () => { const map = new FastMap(); - expect(typeof map.forEach).toBe('function'); + expect(map.forEach).to.be.a('function'); }); it('should iterate over keys and values', () => { @@ -68,13 +69,13 @@ describe('FastMap', () => { const thisArg = {}; map.forEach(function (value, key) { - expect(this).toBe(thisArg); - expect(value).toBe(expectedValues.shift()); - expect(key).toBe(expectedKeys.shift()); + expect(this).to.equal(thisArg); + expect(value).to.equal(expectedValues.shift()); + expect(key).to.equal(expectedKeys.shift()); }, thisArg); - expect(expectedValues.length).toBe(0); - expect(expectedKeys.length).toBe(0); + expect(expectedValues.length).to.equal(0); + expect(expectedKeys.length).to.equal(0); }); }); }); \ No newline at end of file diff --git a/spec/util/Immediate-spec.ts b/spec/util/Immediate-spec.ts index 8b7527d16d..6cc3e7af94 100644 --- a/spec/util/Immediate-spec.ts +++ b/spec/util/Immediate-spec.ts @@ -1,15 +1,25 @@ +import {expect} from 'chai'; +import * as sinon from 'sinon'; import {ImmediateDefinition} from '../../dist/cjs/util/Immediate'; import * as Rx from '../../dist/cjs/Rx'; -import {DoneSignature} from '../helpers/test-helper'; declare const __root__: any; /** @test {ImmediateDefinition} */ describe('ImmediateDefinition', () => { + let sandbox; + beforeEach(function () { + sandbox = sinon.sandbox.create(); + }); + + afterEach(function () { + sandbox.restore(); + }); + it('should have setImmediate and clearImmediate methods', () => { const result = new ImmediateDefinition(__root__); - expect(typeof result.setImmediate).toBe('function'); - expect(typeof result.clearImmediate).toBe('function'); + expect(result.setImmediate).to.be.a('function'); + expect(result.clearImmediate).to.be.a('function'); }); describe('when setImmediate exists on root', () => { @@ -33,8 +43,8 @@ describe('ImmediateDefinition', () => { }); result.clearImmediate(null); - expect(setImmediateCalled).toBeTruthy(); - expect(clearImmediateCalled).toBeTruthy(); + expect(setImmediateCalled).to.be.ok; + expect(clearImmediateCalled).to.be.ok; }); }); @@ -43,28 +53,28 @@ describe('ImmediateDefinition', () => { const instance = { root: { process: { - nextTick: jasmine.createSpy('nextTick') + nextTick: sinon.spy() } }, runIfPresent: () => { //noop }, - partiallyApplied: jasmine.createSpy('partiallyApplied'), - addFromSetImmediateArguments: jasmine.createSpy('addFromSetImmediateArguments').and.returnValue(123456) + partiallyApplied: sinon.spy(), + addFromSetImmediateArguments: sinon.stub().returns(123456) }; const setImmediateImpl = ImmediateDefinition.prototype.createProcessNextTickSetImmediate.call(instance); - expect(typeof setImmediateImpl).toBe('function'); + expect(setImmediateImpl).to.be.a('function'); const action = () => { //noop }; const handle = setImmediateImpl(action); - expect(handle).toBe(123456); - expect(instance.addFromSetImmediateArguments).toHaveBeenCalled(); - expect(instance.partiallyApplied).toHaveBeenCalledWith(instance.runIfPresent, handle); + expect(handle).to.equal(123456); + expect(instance.addFromSetImmediateArguments).have.been.called; + expect(instance.partiallyApplied).have.been.calledWith(instance.runIfPresent, handle); }); }); @@ -77,32 +87,32 @@ describe('ImmediateDefinition', () => { addEventListener: (name: any, callback: any) => { addEventListenerCalledWith = [name, callback]; }, - postMessage: jasmine.createSpy('root.postMessage'), + postMessage: sinon.spy(), Math: { - random: jasmine.createSpy('Math.random').and.returnValue(42) + random: sinon.stub().returns(42) } }, - runIfPresent: jasmine.createSpy('runIfPresent'), - addFromSetImmediateArguments: jasmine.createSpy('addFromSetImmediateArguments').and.returnValue(123456) + runIfPresent: sinon.spy(), + addFromSetImmediateArguments: sinon.stub().returns(123456) }; const setImmediateImpl = ImmediateDefinition.prototype.createPostMessageSetImmediate.call(instance); - expect(typeof setImmediateImpl).toBe('function'); - expect(addEventListenerCalledWith[0]).toBe('message'); + expect(setImmediateImpl).to.be.a('function'); + expect(addEventListenerCalledWith[0]).to.equal('message'); addEventListenerCalledWith[1]({ data: 'setImmediate$42$123456', source: instance.root }); - expect(instance.runIfPresent).toHaveBeenCalledWith(123456); + expect(instance.runIfPresent).have.been.calledWith(123456); const action = () => { //noop }; const handle = setImmediateImpl(action); - expect(handle).toBe(123456); - expect(instance.addFromSetImmediateArguments).toHaveBeenCalled(); - expect(instance.root.postMessage).toHaveBeenCalledWith('setImmediate$42$123456', '*'); + expect(handle).to.equal(123456); + expect(instance.addFromSetImmediateArguments).have.been.called; + expect(instance.root.postMessage).have.been.calledWith('setImmediate$42$123456', '*'); }); }); @@ -110,7 +120,7 @@ describe('ImmediateDefinition', () => { it('should create the proper flavor of setImmediate that uses message channels', () => { const port1 = {}; const port2 = { - postMessage: jasmine.createSpy('MessageChannel.port2.postMessage') + postMessage: sinon.spy() }; function MockMessageChannel() { @@ -122,26 +132,26 @@ describe('ImmediateDefinition', () => { root: { MessageChannel: MockMessageChannel }, - runIfPresent: jasmine.createSpy('runIfPresent'), - addFromSetImmediateArguments: jasmine.createSpy('addFromSetImmediateArguments').and.returnValue(123456) + runIfPresent: sinon.spy(), + addFromSetImmediateArguments: sinon.stub().returns(123456) }; const setImmediateImpl = ImmediateDefinition.prototype.createMessageChannelSetImmediate.call(instance); - expect(typeof setImmediateImpl).toBe('function'); - expect(typeof (port1).onmessage).toBe('function'); + expect(setImmediateImpl).to.be.a('function'); + expect((port1).onmessage).to.be.a('function'); (port1).onmessage({ data: 'something' }); - expect(instance.runIfPresent).toHaveBeenCalledWith('something'); + expect(instance.runIfPresent).have.been.calledWith('something'); const action = () => { //noop }; const handle = setImmediateImpl(action); - expect(handle).toBe(123456); - expect(port2.postMessage).toHaveBeenCalledWith(123456); + expect(handle).to.equal(123456); + expect(port2.postMessage).have.been.calledWith(123456); }); }); @@ -152,36 +162,36 @@ describe('ImmediateDefinition', () => { const instance = { root: { document: { - createElement: jasmine.createSpy('document.createElement').and.returnValue(fakeScriptElement), + createElement: sinon.stub().returns(fakeScriptElement), documentElement: { - appendChild: jasmine.createSpy('documentElement.appendChild'), - removeChild: jasmine.createSpy('documentElement.removeChild') + appendChild: sinon.spy(), + removeChild: sinon.spy(), } } }, - runIfPresent: jasmine.createSpy('runIfPresent'), - addFromSetImmediateArguments: jasmine.createSpy('addFromSetImmediateArguments').and.returnValue(123456) + runIfPresent: sinon.spy(), + addFromSetImmediateArguments: sinon.stub().returns(123456) }; const setImmediateImpl = ImmediateDefinition.prototype.createReadyStateChangeSetImmediate.call(instance); - expect(typeof setImmediateImpl).toBe('function'); + expect(setImmediateImpl).to.be.a('function'); const action = () => { //noop }; const handle = setImmediateImpl(action); - expect(handle).toBe(123456); - expect(instance.root.document.createElement).toHaveBeenCalledWith('script'); - expect(typeof (fakeScriptElement).onreadystatechange).toBe('function'); - expect(instance.root.document.documentElement.appendChild).toHaveBeenCalledWith(fakeScriptElement); + expect(handle).to.equal(123456); + expect(instance.root.document.createElement).have.been.calledWith('script'); + expect((fakeScriptElement).onreadystatechange).to.be.a('function'); + expect(instance.root.document.documentElement.appendChild).have.been.calledWith(fakeScriptElement); (fakeScriptElement).onreadystatechange(); - expect(instance.runIfPresent).toHaveBeenCalledWith(handle); - expect((fakeScriptElement).onreadystatechange).toBe(null); - expect(instance.root.document.documentElement.removeChild).toHaveBeenCalledWith(fakeScriptElement); + expect(instance.runIfPresent).have.been.calledWith(handle); + expect((fakeScriptElement).onreadystatechange).to.be.a('null'); + expect(instance.root.document.documentElement.removeChild).have.been.calledWith(fakeScriptElement); }); }); @@ -191,19 +201,19 @@ describe('ImmediateDefinition', () => { const nextTickImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(true); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'createProcessNextTickSetImmediate').and.returnValue(nextTickImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(true); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'createProcessNextTickSetImmediate').returns(nextTickImpl); const result = new ImmediateDefinition({}); - expect(ImmediateDefinition.prototype.canUseProcessNextTick).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUsePostMessage).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseMessageChannel).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.createProcessNextTickSetImmediate).toHaveBeenCalled(); - expect(result.setImmediate).toBe(nextTickImpl); + expect(ImmediateDefinition.prototype.canUseProcessNextTick).have.been.called; + expect(ImmediateDefinition.prototype.canUsePostMessage).not.have.been.called; + expect(ImmediateDefinition.prototype.canUseMessageChannel).not.have.been.called; + expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.have.been.called; + expect(ImmediateDefinition.prototype.createProcessNextTickSetImmediate).have.been.called; + expect(result.setImmediate).to.equal(nextTickImpl); }); }); @@ -212,19 +222,19 @@ describe('ImmediateDefinition', () => { const postMessageImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(true); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'createPostMessageSetImmediate').and.returnValue(postMessageImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(true); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'createPostMessageSetImmediate').returns(postMessageImpl); const result = new ImmediateDefinition({}); - expect(ImmediateDefinition.prototype.canUseProcessNextTick).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUsePostMessage).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseMessageChannel).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.createPostMessageSetImmediate).toHaveBeenCalled(); - expect(result.setImmediate).toBe(postMessageImpl); + expect(ImmediateDefinition.prototype.canUseProcessNextTick).have.been.called; + expect(ImmediateDefinition.prototype.canUsePostMessage).have.been.called; + expect(ImmediateDefinition.prototype.canUseMessageChannel).not.have.been.called; + expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.have.been.called; + expect(ImmediateDefinition.prototype.createPostMessageSetImmediate).have.been.called; + expect(result.setImmediate).to.equal(postMessageImpl); }); }); @@ -233,19 +243,19 @@ describe('ImmediateDefinition', () => { const messageChannelImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(true); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'createMessageChannelSetImmediate').and.returnValue(messageChannelImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(true); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'createMessageChannelSetImmediate').returns(messageChannelImpl); const result = new ImmediateDefinition({}); - expect(ImmediateDefinition.prototype.canUseProcessNextTick).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUsePostMessage).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseMessageChannel).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.createMessageChannelSetImmediate).toHaveBeenCalled(); - expect(result.setImmediate).toBe(messageChannelImpl); + expect(ImmediateDefinition.prototype.canUseProcessNextTick).have.been.called; + expect(ImmediateDefinition.prototype.canUsePostMessage).have.been.called; + expect(ImmediateDefinition.prototype.canUseMessageChannel).have.been.called; + expect(ImmediateDefinition.prototype.canUseReadyStateChange).not.have.been.called; + expect(ImmediateDefinition.prototype.createMessageChannelSetImmediate).have.been.called; + expect(result.setImmediate).to.equal(messageChannelImpl); }); }); @@ -254,19 +264,19 @@ describe('ImmediateDefinition', () => { const readyStateChangeImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(true); - spyOn(ImmediateDefinition.prototype, 'createReadyStateChangeSetImmediate').and.returnValue(readyStateChangeImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(true); + sandbox.stub(ImmediateDefinition.prototype, 'createReadyStateChangeSetImmediate').returns(readyStateChangeImpl); const result = new ImmediateDefinition({}); - expect(ImmediateDefinition.prototype.canUseProcessNextTick).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUsePostMessage).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseMessageChannel).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseReadyStateChange).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.createReadyStateChangeSetImmediate).toHaveBeenCalled(); - expect(result.setImmediate).toBe(readyStateChangeImpl); + expect(ImmediateDefinition.prototype.canUseProcessNextTick).have.been.called; + expect(ImmediateDefinition.prototype.canUsePostMessage).have.been.called; + expect(ImmediateDefinition.prototype.canUseMessageChannel).have.been.called; + expect(ImmediateDefinition.prototype.canUseReadyStateChange).have.been.called; + expect(ImmediateDefinition.prototype.createReadyStateChangeSetImmediate).have.been.called; + expect(result.setImmediate).to.equal(readyStateChangeImpl); }); }); @@ -275,19 +285,19 @@ describe('ImmediateDefinition', () => { const setTimeoutImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'createSetTimeoutSetImmediate').and.returnValue(setTimeoutImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'createSetTimeoutSetImmediate').returns(setTimeoutImpl); const result = new ImmediateDefinition({}); - expect(ImmediateDefinition.prototype.canUseProcessNextTick).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUsePostMessage).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseMessageChannel).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.canUseReadyStateChange).toHaveBeenCalled(); - expect(ImmediateDefinition.prototype.createSetTimeoutSetImmediate).toHaveBeenCalled(); - expect(result.setImmediate).toBe(setTimeoutImpl); + expect(ImmediateDefinition.prototype.canUseProcessNextTick).have.been.called; + expect(ImmediateDefinition.prototype.canUsePostMessage).have.been.called; + expect(ImmediateDefinition.prototype.canUseMessageChannel).have.been.called; + expect(ImmediateDefinition.prototype.canUseReadyStateChange).have.been.called; + expect(ImmediateDefinition.prototype.createSetTimeoutSetImmediate).have.been.called; + expect(result.setImmediate).to.equal(setTimeoutImpl); }); }); }); @@ -295,15 +305,15 @@ describe('ImmediateDefinition', () => { describe('partiallyApplied', () => { describe('when passed a function as the first argument', () => { it('should return a function that takes no arguments and will be called with the passed arguments', () => { - const fn = jasmine.createSpy('spy'); + const fn = sinon.spy(); const result = ImmediateDefinition.prototype.partiallyApplied(fn, 'arg1', 'arg2', 'arg3'); - expect(typeof result).toBe('function'); - expect(fn).not.toHaveBeenCalled(); + expect(result).to.be.a('function'); + expect(fn).not.have.been.called; result(); - expect(fn).toHaveBeenCalledWith('arg1', 'arg2', 'arg3'); + expect(fn).have.been.calledWith('arg1', 'arg2', 'arg3'); }); }); @@ -313,11 +323,11 @@ describe('ImmediateDefinition', () => { const fnStr = '__wasCalled = true;'; const result = ImmediateDefinition.prototype.partiallyApplied(fnStr); - expect(typeof result).toBe('function'); + expect(result).to.be.a('function'); result(); - expect(__root__.__wasCalled).toEqual(true); + expect(__root__.__wasCalled).to.be.true; delete __root__.__wasCalled; }); @@ -329,7 +339,7 @@ describe('ImmediateDefinition', () => { function MockObject() { //noop } - MockObject.prototype.toString = jasmine.createSpy('Object.prototype.toString').and.returnValue('[object HEYO!]'); + sandbox.stub(MockObject.prototype, 'toString').returns('[object HEYO!]'); const instance = { root: { @@ -339,7 +349,7 @@ describe('ImmediateDefinition', () => { const result = (ImmediateDefinition).prototype.identify.call(instance); - expect(result).toBe('[object HEYO!]'); + expect(result).to.equal('[object HEYO!]'); }); }); @@ -350,13 +360,13 @@ describe('ImmediateDefinition', () => { root: { process: {} }, - identify: jasmine.createSpy('identify').and.returnValue('[object it-is-not-a-tumor]') + identify: sinon.stub().returns('[object it-is-not-a-tumor]') }; const result = ImmediateDefinition.prototype.canUseProcessNextTick.call(instance); - expect(result).toBe(false); - expect(instance.identify).toHaveBeenCalledWith(instance.root.process); + expect(result).to.be.false; + expect(instance.identify).have.been.calledWith(instance.root.process); }); }); @@ -366,13 +376,13 @@ describe('ImmediateDefinition', () => { root: { process: {} }, - identify: jasmine.createSpy('identify').and.returnValue('[object process]') + identify: sinon.stub().returns('[object process]') }; const result = ImmediateDefinition.prototype.canUseProcessNextTick.call(instance); - expect(result).toBe(true); - expect(instance.identify).toHaveBeenCalledWith(instance.root.process); + expect(result).to.be.true; + expect(instance.identify).have.been.calledWith(instance.root.process); }); }); }); @@ -391,7 +401,7 @@ describe('ImmediateDefinition', () => { }; ImmediateDefinition.prototype.canUsePostMessage.call(instance); - expect(instance.root.onmessage).toBe(originalOnMessage); + expect(instance.root.onmessage).to.equal(originalOnMessage); }); describe('and postMessage is synchronous', () => { @@ -407,8 +417,8 @@ describe('ImmediateDefinition', () => { }; const result = ImmediateDefinition.prototype.canUsePostMessage.call(instance); - expect(result).toBe(false); - expect(postMessageCalled).toBe(true); + expect(result).to.be.false; + expect(postMessageCalled).to.be.true; }); }); @@ -426,8 +436,8 @@ describe('ImmediateDefinition', () => { }; const result = ImmediateDefinition.prototype.canUsePostMessage.call(instance); - expect(result).toBe(true); - expect(postMessageCalled).toBe(true); + expect(result).to.be.true; + expect(postMessageCalled).to.be.true; }); }); }); @@ -446,7 +456,7 @@ describe('ImmediateDefinition', () => { }; const result = ImmediateDefinition.prototype.canUsePostMessage.call(instance); - expect(result).toBe(false); + expect(result).to.be.false; }); }); }); @@ -459,7 +469,7 @@ describe('ImmediateDefinition', () => { const result = ImmediateDefinition.prototype.canUsePostMessage.call(instance); - expect(result).toBe(false); + expect(result).to.be.false; }); }); }); @@ -476,7 +486,7 @@ describe('ImmediateDefinition', () => { const result = ImmediateDefinition.prototype.canUseMessageChannel.call(instance); - expect(result).toBe(true); + expect(result).to.be.true; }); it('should return false if MessageChannel does NOT exist', () => { @@ -486,7 +496,7 @@ describe('ImmediateDefinition', () => { const result = ImmediateDefinition.prototype.canUseMessageChannel.call(instance); - expect(result).toBe(false); + expect(result).to.be.false; }); }); @@ -500,15 +510,15 @@ describe('ImmediateDefinition', () => { const instance = { root: { document: { - createElement: jasmine.createSpy('document.createElement').and.returnValue(fakeScriptElement) + createElement: sinon.stub().returns(fakeScriptElement) } } }; const result = ImmediateDefinition.prototype.canUseReadyStateChange.call(instance); - expect(result).toBe(true); - expect(instance.root.document.createElement).toHaveBeenCalledWith('script'); + expect(result).to.be.true; + expect(instance.root.document.createElement).have.been.calledWith('script'); }); it('should return false if created script elements do NOT have an onreadystatechange property', () => { @@ -517,15 +527,15 @@ describe('ImmediateDefinition', () => { const instance = { root: { document: { - createElement: jasmine.createSpy('document.createElement').and.returnValue(fakeScriptElement) + createElement: sinon.stub().returns(fakeScriptElement) } } }; const result = ImmediateDefinition.prototype.canUseReadyStateChange.call(instance); - expect(result).toBe(false); - expect(instance.root.document.createElement).toHaveBeenCalledWith('script'); + expect(result).to.be.false; + expect(instance.root.document.createElement).have.been.calledWith('script'); }); }); @@ -536,7 +546,7 @@ describe('ImmediateDefinition', () => { const result = ImmediateDefinition.prototype.canUseReadyStateChange.call(instance); - expect(result).toBe(false); + expect(result).to.be.false; }); }); @@ -547,7 +557,7 @@ describe('ImmediateDefinition', () => { const instance = { tasksByHandle: {}, nextHandle: 42, - partiallyApplied: jasmine.createSpy('partiallyApplied').and.returnValue(partiallyAppliedResult) + partiallyApplied: sinon.stub().returns(partiallyAppliedResult) }; const args = [() => { @@ -556,9 +566,9 @@ describe('ImmediateDefinition', () => { const handle = ImmediateDefinition.prototype.addFromSetImmediateArguments.call(instance, args); - expect(handle).toBe(42); - expect(instance.nextHandle).toBe(43); - expect(instance.tasksByHandle[42]).toBe(partiallyAppliedResult); + expect(handle).to.equal(42); + expect(instance.nextHandle).to.equal(43); + expect(instance.tasksByHandle[42]).to.equal(partiallyAppliedResult); }); }); @@ -567,22 +577,22 @@ describe('ImmediateDefinition', () => { const setTimeoutImpl = () => { //noop }; - spyOn(ImmediateDefinition.prototype, 'canUseProcessNextTick').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUsePostMessage').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseMessageChannel').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'canUseReadyStateChange').and.returnValue(false); - spyOn(ImmediateDefinition.prototype, 'createSetTimeoutSetImmediate').and.returnValue(setTimeoutImpl); + sandbox.stub(ImmediateDefinition.prototype, 'canUseProcessNextTick').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUsePostMessage').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseMessageChannel').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'canUseReadyStateChange').returns(false); + sandbox.stub(ImmediateDefinition.prototype, 'createSetTimeoutSetImmediate').returns(setTimeoutImpl); const Immediate = new ImmediateDefinition({}); Immediate.tasksByHandle[123456] = () => { //noop }; - expect('123456' in Immediate.tasksByHandle).toBe(true); + expect('123456' in Immediate.tasksByHandle).to.be.true; Immediate.clearImmediate(123456); - expect('123456' in Immediate.tasksByHandle).toBe(false); + expect('123456' in Immediate.tasksByHandle).to.be.false; }); }); @@ -594,24 +604,24 @@ describe('ImmediateDefinition', () => { const instance = { root: { - setTimeout: jasmine.createSpy('setTimeout'), + setTimeout: sinon.spy(), Object: Object }, currentlyRunningATask: true, - partiallyApplied: jasmine.createSpy('partiallyApplied').and.returnValue(mockApplied) + partiallyApplied: sinon.stub().returns(mockApplied) }; ImmediateDefinition.prototype.runIfPresent.call(instance, 123456); - expect(instance.partiallyApplied).toHaveBeenCalledWith((instance).runIfPresent, 123456); - expect(instance.root.setTimeout).toHaveBeenCalledWith(mockApplied, 0); + expect(instance.partiallyApplied).have.been.calledWith((instance).runIfPresent, 123456); + expect(instance.root.setTimeout).have.been.calledWith(mockApplied, 0); }); it('should not error if there is no task currently running and the handle passed is not found', () => { expect(() => { const instance = { root: { - setTimeout: jasmine.createSpy('setTimeout'), + setTimeout: sinon.spy(), Object: Object }, currentlyRunningATask: false, @@ -619,27 +629,32 @@ describe('ImmediateDefinition', () => { }; ImmediateDefinition.prototype.runIfPresent.call(instance, 888888); - }).not.toThrow(); + }).not.to.throw(); }); describe('when a task is found for the handle', () => { it('should execute the task and clean up after', () => { const instance = { root: { - setTimeout: jasmine.createSpy('setTimeout'), + setTimeout: sinon.spy(), Object: Object }, currentlyRunningATask: false, tasksByHandle: {}, - clearImmediate: jasmine.createSpy('clearImmediate') + clearImmediate: sinon.spy() }; - instance.tasksByHandle[123456] = jasmine.createSpy('task').and.callFake(() => { - expect(instance.currentlyRunningATask).toBe(true); + const spy = sinon.stub(); + + spy({ + task: function () { + expect(instance.currentlyRunningATask).to.be.true; + } }); + instance.tasksByHandle[123456] = spy; ImmediateDefinition.prototype.runIfPresent.call(instance, 123456); - expect(instance.clearImmediate).toHaveBeenCalledWith(123456); + expect(instance.clearImmediate).have.been.calledWith(123456); }); }); }); @@ -652,35 +667,35 @@ describe('ImmediateDefinition', () => { const instance = { root: { - setTimeout: jasmine.createSpy('setTimeout') + setTimeout: sinon.spy() }, - addFromSetImmediateArguments: jasmine.createSpy('addFromSetImmediateArguments').and.returnValue(123456), + addFromSetImmediateArguments: sinon.stub().returns(123456), runIfPresent: function () { //noop }, - partiallyApplied: jasmine.createSpy('partiallyApplied').and.returnValue(mockApplied) + partiallyApplied: sinon.stub().returns(mockApplied) }; const setImmediateImpl = ImmediateDefinition.prototype.createSetTimeoutSetImmediate.call(instance); const handle = setImmediateImpl(); - expect(handle).toBe(123456); - expect(instance.addFromSetImmediateArguments).toHaveBeenCalled(); - expect(instance.root.setTimeout).toHaveBeenCalledWith(mockApplied, 0); + expect(handle).to.equal(123456); + expect(instance.addFromSetImmediateArguments).have.been.called; + expect(instance.root.setTimeout).have.been.calledWith(mockApplied, 0); }); }); describe('integration test', () => { - it('should work', (done: DoneSignature) => { + it('should work', (done: MochaDone) => { const results = []; Rx.Observable.from([1, 2, 3], Rx.Scheduler.asap) .subscribe((x: number) => { results.push(x); }, () => { - done.fail(); + done(new Error('should not be called')); }, () => { - expect(results).toEqual([1, 2, 3]); + expect(results).to.deep.equal([1, 2, 3]); done(); }); }); diff --git a/spec/util/MapPolyfill-spec.ts b/spec/util/MapPolyfill-spec.ts index 1e91c3b9bb..bbf960bb88 100644 --- a/spec/util/MapPolyfill-spec.ts +++ b/spec/util/MapPolyfill-spec.ts @@ -1,9 +1,10 @@ +import {expect} from 'chai'; import {MapPolyfill} from '../../dist/cjs/util/MapPolyfill'; /** @test {MapPolyfill} */ describe('MapPolyfill', () => { it('should exist', () => { - expect(typeof MapPolyfill).toBe('function'); + expect(MapPolyfill).to.be.a('function'); }); it('should act like a hashtable that accepts objects as keys', () => { @@ -15,10 +16,10 @@ describe('MapPolyfill', () => { map.set(key1, 'yo'); map.set(key2, 'what up'); - expect(map.get('test')).toBe('hi'); - expect(map.get(key1)).toBe('yo'); - expect(map.get(key2)).toBe('what up'); - expect(map.size).toBe(3); + expect(map.get('test')).to.equal('hi'); + expect(map.get(key1)).to.equal('yo'); + expect(map.get(key2)).to.equal('what up'); + expect(map.size).to.equal(3); }); it('should allow setting keys twice', () => { @@ -28,8 +29,8 @@ describe('MapPolyfill', () => { map.set(key1, 'sing'); map.set(key1, 'yodel'); - expect(map.get(key1)).toBe('yodel'); - expect(map.size).toBe(1); + expect(map.get(key1)).to.equal('yodel'); + expect(map.size).to.equal(1); }); it('should have a delete method that removes keys', () => { @@ -37,18 +38,18 @@ describe('MapPolyfill', () => { const key1 = {}; map.set(key1, 'sing'); - expect(map.size).toBe(1); + expect(map.size).to.equal(1); map.delete(key1); - expect(map.size).toBe(0); - expect(map.get(key1)).toBe(undefined); + expect(map.size).to.equal(0); + expect(map.get(key1)).to.be.a('undefined'); }); describe('prototype.forEach', () => { it('should exist', () => { const map = new MapPolyfill(); - expect(typeof map.forEach).toBe('function'); + expect(map.forEach).to.be.a('function'); }); it('should iterate over keys and values', () => { @@ -65,13 +66,13 @@ describe('MapPolyfill', () => { //intentionally not using lambda to avoid typescript's this context capture map.forEach(function (value, key) { - expect(this).toBe(thisArg); - expect(value).toBe(expectedValues.shift()); - expect(key).toBe(expectedKeys.shift()); + expect(this).to.equal(thisArg); + expect(value).to.equal(expectedValues.shift()); + expect(key).to.equal(expectedKeys.shift()); }, thisArg); - expect(expectedValues.length).toBe(0); - expect(expectedKeys.length).toBe(0); + expect(expectedValues.length).to.equal(0); + expect(expectedKeys.length).to.equal(0); }); }); }); \ No newline at end of file