From f95fdcf8a40b3a7580f908c343a164789b60a18e Mon Sep 17 00:00:00 2001 From: bekzod Date: Thu, 20 Jul 2017 11:14:25 +0500 Subject: [PATCH 1/2] fixed bug when truthy values would not filter correctly --- lib/rsvp/filter.js | 2 +- test/extension-test.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/rsvp/filter.js b/lib/rsvp/filter.js index b1222119..90b3205a 100644 --- a/lib/rsvp/filter.js +++ b/lib/rsvp/filter.js @@ -47,7 +47,7 @@ class FilterEnumerator extends Enumerator { } } else { this._remaining--; - if (value !== true) { + if (!value) { this._result[i] = EMPTY_OBJECT; } } diff --git a/test/extension-test.js b/test/extension-test.js index c1dc768c..e2555db7 100644 --- a/test/extension-test.js +++ b/test/extension-test.js @@ -2418,7 +2418,7 @@ describe("RSVP extensions", function() { }).catch(done); }); - it("filters falsy values correctly", function(done){ + it("filters falsy values correctly 1", function(done){ var promises = [ RSVP.resolve(false), RSVP.resolve(undefined), @@ -2433,6 +2433,37 @@ describe("RSVP extensions", function() { }).catch(done); }); + it("filters falsy values correctly 2", function(done){ + var promises = [ + RSVP.resolve(false), + RSVP.resolve(undefined), + RSVP.resolve(null), + RSVP.resolve(0), + RSVP.resolve('') + ]; + + RSVP.filter(promises, function(val){ return val; }).then(function(results){ + assert.equal(results.length, 0); + done(); + }).catch(done); + }); + + it("filters truthy values correctly", function(done){ + var promises = [ + RSVP.resolve(true), + RSVP.resolve(1), + RSVP.resolve(-10), + RSVP.resolve('a'), + RSVP.resolve({}), + RSVP.resolve([]) + ]; + + RSVP.filter(promises, function(val){ return val; }).then(function(results){ + assert.deepEqual(results, [true, 1, -10, 'a', {}, []]); + done(); + }).catch(done); + }); + it("catches error thrown from filterFn", function(done){ var throwerFilter = function(val) { if (val === 2) { From 81af1f409050ca3a05ae0aecafc89cd616f3bb13 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Thu, 20 Jul 2017 11:48:15 -0700 Subject: [PATCH 2/2] =?UTF-8?q?release=20v4.0.1=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 675d0755..b4399ec3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rsvp", "namespace": "RSVP", - "version": "4.0.0", + "version": "4.0.1", "description": "A lightweight library that provides tools for organizing asynchronous code", "main": "dist/rsvp.js", "module": "dist/rsvp.es.js",