Swap-Aggregator-Subgraph/node_modules/looper/test/test.js
2022-07-03 07:27:35 +05:30

38 lines
629 B
JavaScript

var tape = require('tape')
var looper = require('../')
tape('n=1000000, with no RangeError', function (t) {
var n = 1000000, c = 0
looper(function (next) {
c ++
if(--n) return next()
t.equal(c, 1000000)
t.end()
})
})
tape('async is okay', function (t) {
var n = 100, c = 0
looper(function (next) {
c ++
if(--n) return setTimeout(next)
t.equal(c, 100)
t.end()
})
})
tape('sometimes async is okay', function (t) {
var i = 1000; c = 0
looper(function (next) {
c++
if(--i) return Math.random() < 0.1 ? setTimeout(next) : next()
t.equal(c, 1000)
t.end()
})
})