From 43304a75b7a1b9613cb7812bf4e053b3f250fda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gabriel=20Lima?= Date: Thu, 10 Dec 2015 15:15:55 -0300 Subject: [PATCH] test(findIndex): add more test cases --- spec/operators/findindex-spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/operators/findindex-spec.js b/spec/operators/findindex-spec.js index 59b76482cd..2a63fbd866 100644 --- a/spec/operators/findindex-spec.js +++ b/spec/operators/findindex-spec.js @@ -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 = '^ !';