From 14d4d0f196d9a26801bb261d16105b59292bb03c Mon Sep 17 00:00:00 2001 From: Saurav Azad <3856934+sauravazad@users.noreply.github.com> Date: Tue, 29 Jun 2021 03:17:36 +0530 Subject: Improving tests case coverage (#1754) * Adding test case when invalid callback is provided to each () * adding nyc ignore block * Adding new test cases for drain to be called if empty data is pushed --- lib/internal/consoleFunc.js | 5 ++++- test/each.js | 9 +++++++++ test/priorityQueue.js | 10 ++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/internal/consoleFunc.js b/lib/internal/consoleFunc.js index d2c1cb1..4ce5c9b 100644 --- a/lib/internal/consoleFunc.js +++ b/lib/internal/consoleFunc.js @@ -2,12 +2,15 @@ import wrapAsync from './wrapAsync'; export default function consoleFunc(name) { return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => { + /* istanbul ignore else */ if (typeof console === 'object') { + /* istanbul ignore else */ if (err) { + /* istanbul ignore else */ if (console.error) { console.error(err); } - } else if (console[name]) { + } else if (console[name]) { /* istanbul ignore else */ resultArgs.forEach(x => console[name](x)); } } diff --git a/test/each.js b/test/each.js index eb12842..7b83476 100644 --- a/test/each.js +++ b/test/each.js @@ -96,6 +96,15 @@ describe("each", () => { async.each([1], eachNoCallbackIteratee.bind(this, done)); }); + it('each no callback', async (done) => { + try { + async.each([1], 'INVALID_CALL_BACK', () => {}); + } catch(err) { + expect(err.message).to.equal('expected a function') + done() + } + }); + it('eachSeries', function(done) { var args = []; async.eachSeries([1,3,2], eachIteratee.bind(this, args), (err) => { diff --git a/test/priorityQueue.js b/test/priorityQueue.js index 96936fd..564a0d6 100644 --- a/test/priorityQueue.js +++ b/test/priorityQueue.js @@ -49,8 +49,15 @@ describe('priorityQueue', () => { ]); expect(q.concurrency).to.equal(1); expect(q.length()).to.equal(0); - done(); + q.push([]) + expect(q.length()).to.equal(0) + done() }); + try { + q.push(5, 5, 'NOT_A_FUNCTION') + } catch(e) { + expect(e.message).to.equal('task callback must be a function') + } }); it('concurrency', (done) => { @@ -276,4 +283,3 @@ describe('priorityQueue', () => { q.push([], 1, () => {}); }); }); - -- cgit v1.2.1