From: Justin Wind Date: Sat, 13 Jan 2024 01:51:44 +0000 (-0800) Subject: fix _reset behavior X-Git-Tag: v1.0.2~1 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=5001ce3f7b9ba4fb13bdee4fa220635567c0f2a8;p=squeep-test-helper fix _reset behavior --- diff --git a/lib/stub-logger.js b/lib/stub-logger.js index 6df2b94..c1a4779 100644 --- a/lib/stub-logger.js +++ b/lib/stub-logger.js @@ -2,13 +2,14 @@ const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require -const nop = () => { /* */ }; +const nop = () => undefined; class StubLogger { constructor(verbose = false) { const logger = (process.env.VERBOSE_TESTS || verbose) ? console : StubLogger._nullLogger; Object.keys(StubLogger._nullLogger).forEach((level) => { this[level] = logger[level]; // eslint-disable-line security/detect-object-injection + sinon.spy(this, level); }); } @@ -27,7 +28,7 @@ class StubLogger { } _reset() { - Object.keys(StubLogger._nullLogger).forEach((level) => sinon.spy(this, level)); + StubLogger._levels.forEach((level) => this[level].resetHistory()); // eslint-disable-line security/detect-object-injection } } diff --git a/test/lib/stub-logger.js b/test/lib/stub-logger.js index e2fa672..86c2213 100644 --- a/test/lib/stub-logger.js +++ b/test/lib/stub-logger.js @@ -19,6 +19,12 @@ describe('StubLogger', function () { logger._reset(); }); it('covers levels', logAllLevels); + it('covers reset', function () { + logAllLevels(); + logger._reset(); + logAllLevels(); + logger._reset(); + }); }); // null logger describe('console logger', function () { beforeEach(function () { @@ -26,5 +32,11 @@ describe('StubLogger', function () { logger._reset(); }); it('covers levels', logAllLevels); + it('covers reset', function () { + logAllLevels(); + logger._reset(); + logAllLevels(); + logger._reset(); + }); }); // null logger }); // StubLogger \ No newline at end of file