From 4bd482b2cd816f01afa752446f8721f4e75a2fa5 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Thu, 1 Aug 2024 15:32:19 -0700 Subject: [PATCH] throw if sinon not provided --- lib/stub-logger.js | 3 +++ test/lib/stub-logger.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/stub-logger.js b/lib/stub-logger.js index 428fdd0..9564c84 100644 --- a/lib/stub-logger.js +++ b/lib/stub-logger.js @@ -1,7 +1,10 @@ 'use strict'; +const assert = require('node:assert'); + class StubLogger { constructor(sinon, verbose = false) { + assert.strictEqual(sinon?.constructor?.name, 'Sandbox', 'sinon dependency not recognized'); this.sinon = sinon; const logger = (process.env.VERBOSE_TESTS || verbose) ? console : this.constructor._nullLogger; Object.keys(this.constructor._nullLogger).forEach((level) => { diff --git a/test/lib/stub-logger.js b/test/lib/stub-logger.js index 3d5bb6a..528fba5 100644 --- a/test/lib/stub-logger.js +++ b/test/lib/stub-logger.js @@ -17,6 +17,11 @@ describe('StubLogger', function () { assert(logger[level][property]); }); } + describe('sinon dependency', function () { + it('is required', function () { + assert.throws(() => new StubLogger(), assert.AssertionError); + }); + }); describe('null logger', function () { beforeEach(function () { logger = new StubLogger(sinon); @@ -59,4 +64,4 @@ describe('StubLogger', function () { assertAllLevels('notCalled'); }); }); // console logger -}); // StubLogger \ No newline at end of file +}); // StubLogger -- 2.45.2