Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for publishBehavior and publishReplay #235

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions spec/operators/publishBehavior-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Observable.prototype.publishBehavior()', function () {
done();
});

it('should emit default value to observer after completed', function (done) {
it('should not emit next events to observer after completed', function (done) {
var results = [];

var source = new Observable(function (observer) {
Expand All @@ -55,14 +55,13 @@ describe('Observable.prototype.publishBehavior()', function () {
});

var connectable = source.publishBehavior(0);

connectable.connect();

connectable.subscribe(function (x) {
results.push(x);
});

expect(results).toEqual([0]);
expect(results).toEqual([]);
done();
});

Expand Down
24 changes: 23 additions & 1 deletion spec/operators/publishReplay-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ describe('Observable.prototype.publishReplay()', function () {
done();
});

it('should emit replayed events to observer after completed', function (done) {
var results = [];

var source = new Observable(function (observer) {
observer.next(1);
observer.next(2);
observer.next(3);
observer.next(4);
observer.complete();
});

var connectable = source.publishReplay(2);
connectable.connect();

connectable.subscribe(function (x) {
results.push(x);
});

expect(results).toEqual([3, 4]);
done();
});

it('should allow you to reconnect by subscribing again', function (done) {
var expected = [1, 2, 3, 4];
var i = 0;
Expand All @@ -99,4 +121,4 @@ describe('Observable.prototype.publishReplay()', function () {

source.connect();
});
});
});
18 changes: 14 additions & 4 deletions spec/subjects/behavior-subject-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals describe, it, expect */
/* globals describe, it, expect, fail */
var Rx = require('../../dist/cjs/Rx');

var BehaviorSubject = Rx.BehaviorSubject;
Expand All @@ -10,23 +10,33 @@ describe('BehaviorSubject', function() {
expect(subject instanceof Rx.Subject).toBe(true);
done();
});

it('should start with an initialization value', function(done) {
var subject = new BehaviorSubject('foo');
var expected = ['foo', 'bar'];
var i = 0;

subject.subscribe(function(x) {
expect(x).toBe(expected[i++]);
}, null,
function(){
done();
});

// HACK
Rx.Scheduler.nextTick.schedule(0, null, function(){
subject.next('bar');
subject.complete();
});
});

it('should not replay last value after it completes', function(done) {
var subject = new BehaviorSubject('foo');
subject.next('bar');
subject.next('baz');
subject.complete();
subject.subscribe(function(x) {
fail('subscribeOnNext has been called');
}, null, done);
});
});