Skip to content

Commit

Permalink
test(ScalarObservable): add test cases for thisArg
Browse files Browse the repository at this point in the history
Closes #996.
  • Loading branch information
luisgabriel authored and benlesh committed Dec 14, 2015
1 parent 3c93be1 commit ca04217
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/observables/ScalarObservable-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ describe('ScalarObservable', function () {
expect(r.value).toBe('1!!!');
});

it('should map using a custom thisArg', function () {
var s = new ScalarObservable(1);
var foo = 42;
var selector = function (x) {
expect(this).toEqual(foo);
return x + '!!!';
};
var r = s.map(selector, 42);

expect(r instanceof ScalarObservable).toBe(true);
expect(r.value).toBe('1!!!');
});

it('should return an ErrorObservable if map errors', function () {
var s = new ScalarObservable(1);
var r = s.map(function (x) { throw 'bad!'; });
Expand Down Expand Up @@ -79,6 +92,20 @@ describe('ScalarObservable', function () {
expect(s).toBe(r);
});

it('should filter using a custom thisArg', function () {
var s = new ScalarObservable(1);
var filterer = {
filter1: function (x) { return x > 0; },
filter2: function (x) { return x === 1; }
};

var r = s
.filter(function (x) { return this.filter1(x); }, filterer)
.filter(function (x) { return this.filter2(x); }, filterer);

expect(s).toBe(r);
});

it('should return EmptyObservable if filter does not match', function () {
var s = new ScalarObservable(1);
var r = s.filter(function (x) { return x === 0; });
Expand Down

0 comments on commit ca04217

Please sign in to comment.