Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
dormeiri committed Aug 12, 2024
1 parent f179ac7 commit 01474f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ test('manages rapid successive calls', async t => {
});

test('onDelay', async t => {
const delayedIndices = {};
const delayedIndices = [];
const limit = 10;
const interval = 100;
const delayedExecutions = 20;
const onDelay = (keyPrefix, index) => {
delayedIndices[keyPrefix + index] = true;
delayedIndices.push(keyPrefix + index);
};

const throttled = pThrottle({limit, interval, onDelay})((_keyPrefix, _index) => Date.now());
Expand All @@ -417,13 +417,13 @@ test('onDelay', async t => {
promises.push(throttled('a', index));
}

t.deepEqual(delayedIndices, {});
t.deepEqual(delayedIndices, []);

for (let index = 0; index < delayedExecutions; index++) {
promises.push(throttled('b', index));
}

t.like(delayedIndices, {b0: true, b1: true, b19: true, b20: undefined, a0: undefined});
t.like(delayedIndices, {0: 'b0', 1: 'b1', 19: 'b19', 20: undefined});

await Promise.all(promises);
});

0 comments on commit 01474f0

Please sign in to comment.