Skip to content

Commit

Permalink
test(findIndex): add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
luisgabriel authored and benlesh committed Dec 14, 2015
1 parent 6237339 commit 43304a7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/operators/findindex-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ describe('Observable.prototype.findIndex()', function () {
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should return index of matching element from source emits multiple elements', function () {
var source = hot('--a--b---c-|', { b: 7 });
var subs = '^ !';
var expected = '-----(x|)';

var predicate = function (value) {
return value === 7;
};

expectObservable(source.findIndex(predicate)).toBe(expected, { x: 1 });
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should work with a custom thisArg', function () {
var sourceValues = { b: 7 };
var source = hot('--a--b---c-|', sourceValues);
var subs = '^ !';
var expected = '-----(x|)';

var predicate = function (value) {
return value === this.b;
};
var result = source.findIndex(predicate, sourceValues);

expectObservable(result).toBe(expected, { x: 1 });
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should return negative index if element does not match with predicate', function () {
var source = hot('--a--b--c--|');
var subs = '^ !';
Expand Down

0 comments on commit 43304a7

Please sign in to comment.