summaryrefslogtreecommitdiff
path: root/mocha_test/filter.js
diff options
context:
space:
mode:
Diffstat (limited to 'mocha_test/filter.js')
-rw-r--r--mocha_test/filter.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/mocha_test/filter.js b/mocha_test/filter.js
index 05d9d99..8f13620 100644
--- a/mocha_test/filter.js
+++ b/mocha_test/filter.js
@@ -53,6 +53,37 @@ describe("filter", function () {
});
});
+ 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');