summaryrefslogtreecommitdiff
path: root/mocha_test
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2016-11-14 09:40:37 -0500
committerGitHub <noreply@github.com>2016-11-14 09:40:37 -0500
commit56051dfb17cd3e5d97f796f9e516c22fc2316b6c (patch)
treeca454ba534f40067b35f3ab5a00df4b2eba0948d /mocha_test
parentb4d794c4b9c0c3406007297a06a08525d008ba51 (diff)
parente79952057cb1e439c396f0acc7dee5b635e40ab7 (diff)
downloadasync-56051dfb17cd3e5d97f796f9e516c22fc2316b6c.tar.gz
Merge pull request #1320 from caolan/pr/1297
Pr/1297
Diffstat (limited to 'mocha_test')
-rw-r--r--mocha_test/filter.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/mocha_test/filter.js b/mocha_test/filter.js
index 8b4b268..8f13620 100644
--- a/mocha_test/filter.js
+++ b/mocha_test/filter.js
@@ -41,6 +41,49 @@ describe("filter", function () {
});
});
+ it('filter collection', function(done){
+ var a = {a: 3, b: 1, c: 2};
+ async.filter(a, function(x, callback){
+ callback(null, x % 2);
+ }, function(err, results){
+ expect(err).to.equal(null);
+ expect(results).to.eql([3,1]);
+ expect(a).to.eql({a: 3, b: 1, c: 2});
+ done();
+ });
+ });
+
+ if (typeof Symbol === 'function' && Symbol.iterator) {
+ function makeIterator(array){
+ var nextIndex;
+ let iterator = {
+ next: function(){
+ return nextIndex < array.length ?
+ {value: array[nextIndex++], done: false} :
+ {done: true};
+ }
+ };
+ iterator[Symbol.iterator] = function() {
+ nextIndex = 0; // reset iterator
+ return iterator;
+ };
+ return iterator;
+ }
+
+ it('filter iterator', function(done){
+ var a = makeIterator([500, 20, 100]);
+ async.filter(a, function(x, callback) {
+ setTimeout(function() {
+ callback(null, x > 20);
+ }, x);
+ }, function(err, results){
+ expect(err).to.equal(null);
+ expect(results).to.eql([500, 100]);
+ done();
+ });
+ });
+ }
+
it('filter error', function(done){
async.filter([3,1,2], function(x, callback){
callback('error');