Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Closing issue #331
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpodwysocki committed Nov 13, 2014
1 parent 4a86e35 commit 9d8a8e8
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 218 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ var browsers = [{
'src/core/testing/subscription.js',
'src/core/testing/mockdisposable.js',
'src/core/testing/mockobserver.js',
'src/core/testing/mockpromise.js',
'src/core/testing/hotobservable.js',
'src/core/testing/coldobservable.js',
'src/core/testing/testscheduler.js',
Expand Down
182 changes: 101 additions & 81 deletions dist/rx.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,48 +211,73 @@ var ReactiveTest = Rx.ReactiveTest = {
this.disposes.push(this.scheduler.clock);
};

/** @private */
var MockObserver = (function (_super) {
inherits(MockObserver, _super);

/*
* @constructor
* @prviate
*/
function MockObserver(scheduler) {
_super.call(this);
this.scheduler = scheduler;
this.messages = [];
}

var MockObserverPrototype = MockObserver.prototype;

/*
* @memberOf MockObserverPrototype#
* @prviate
*/
MockObserverPrototype.onNext = function (value) {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnNext(value)));
};

/*
* @memberOf MockObserverPrototype#
* @prviate
*/
MockObserverPrototype.onError = function (exception) {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnError(exception)));
};

/*
* @memberOf MockObserverPrototype#
* @prviate
*/
MockObserverPrototype.onCompleted = function () {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnCompleted()));
};

return MockObserver;
})(Observer);
var MockObserver = (function (__super__) {
inherits(MockObserver, __super__);

function MockObserver(scheduler) {
__super__.call(this);
this.scheduler = scheduler;
this.messages = [];
}

var MockObserverPrototype = MockObserver.prototype;

MockObserverPrototype.onNext = function (value) {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnNext(value)));
};

MockObserverPrototype.onError = function (exception) {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnError(exception)));
};

MockObserverPrototype.onCompleted = function () {
this.messages.push(new Recorded(this.scheduler.clock, Notification.createOnCompleted()));
};

return MockObserver;
})(Observer);

function MockPromise(scheduler, messages) {
var message, notification, observable = this;
this.scheduler = scheduler;
this.messages = messages;
this.subscriptions = [];
this.observers = [];
for (var i = 0, len = this.messages.length; i < len; i++) {
message = this.messages[i];
notification = message.value;
(function (innerNotification) {
scheduler.scheduleAbsoluteWithState(null, message.time, function () {
var obs = observable.observers.slice(0);

for (var j = 0, jLen = obs.length; j < jLen; j++) {
innerNotification.accept(obs[j]);
}
return disposableEmpty;
});
})(notification);
}
}

MockPromise.prototype.then = function (onResolved, onRejected) {
var self = this;

var observer = Rx.Observer.create(
function (x) {
onResolved(x);
var idx = self.observers.indexOf(observer);
self.observers.splice(idx, 1);
},
function (err) {
onRejected(err);
var idx = self.observers.indexOf(observer);
self.observers.splice(idx, 1);
}
);
this.observers.push(observer);

return new MockPromise(this.scheduler, []);
}

var HotObservable = (function (__super__) {

Expand Down Expand Up @@ -296,45 +321,40 @@ var ReactiveTest = Rx.ReactiveTest = {
return HotObservable;
})(Observable);

/** @private */
var ColdObservable = (function (_super) {

function subscribe(observer) {
var message, notification, observable = this;
this.subscriptions.push(new Subscription(this.scheduler.clock));
var index = this.subscriptions.length - 1;
var d = new CompositeDisposable();
for (var i = 0, len = this.messages.length; i < len; i++) {
message = this.messages[i];
notification = message.value;
(function (innerNotification) {
d.add(observable.scheduler.scheduleRelativeWithState(null, message.time, function () {
innerNotification.accept(observer);
return disposableEmpty;
}));
})(notification);
}
return disposableCreate(function () {
observable.subscriptions[index] = new Subscription(observable.subscriptions[index].subscribe, observable.scheduler.clock);
d.dispose();
});
}

inherits(ColdObservable, _super);

/**
* @private
* @constructor
*/
function ColdObservable(scheduler, messages) {
_super.call(this, subscribe);
this.scheduler = scheduler;
this.messages = messages;
this.subscriptions = [];
}

return ColdObservable;
})(Observable);
var ColdObservable = (function (__super__) {

function subscribe(observer) {
var message, notification, observable = this;
this.subscriptions.push(new Subscription(this.scheduler.clock));
var index = this.subscriptions.length - 1;
var d = new CompositeDisposable();
for (var i = 0, len = this.messages.length; i < len; i++) {
message = this.messages[i];
notification = message.value;
(function (innerNotification) {
d.add(observable.scheduler.scheduleRelativeWithState(null, message.time, function () {
innerNotification.accept(observer);
return disposableEmpty;
}));
})(notification);
}
return disposableCreate(function () {
observable.subscriptions[index] = new Subscription(observable.subscriptions[index].subscribe, observable.scheduler.clock);
d.dispose();
});
}

inherits(ColdObservable, __super__);

function ColdObservable(scheduler, messages) {
__super__.call(this, subscribe);
this.scheduler = scheduler;
this.messages = messages;
this.subscriptions = [];
}

return ColdObservable;
})(Observable);

/** Virtual time scheduler used for testing applications and libraries built using Reactive Extensions. */
Rx.TestScheduler = (function (__super__) {
Expand Down
2 changes: 1 addition & 1 deletion dist/rx.testing.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rx.testing.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d8a8e8

Please sign in to comment.