From 160714fdedc86e77bda9229df479fd95acf31d3e Mon Sep 17 00:00:00 2001 From: sucem029 Date: Mon, 26 May 2025 13:29:38 +0200 Subject: [PATCH] Added unit tests for utils.compileETag to cover valid and invalid inputs --- test/utils.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/utils.js b/test/utils.js index b11b26680bd..53dc093cd7d 100644 --- a/test/utils.js +++ b/test/utils.js @@ -80,3 +80,29 @@ describe('utils.wetag(body, encoding)', function(){ 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) + +describe('utils.compileETag()', function () { + it('should return generateETag for true', function () { + const fn = utils.compileETag(true); + assert.strictEqual(typeof fn, 'function'); + }); + + it('should return undefined for false', function () { + assert.strictEqual(utils.compileETag(false), undefined); + }); + + it('should return generateETag for string values "strong" and "weak"', function () { + assert.strictEqual(typeof utils.compileETag('strong'), 'function'); + assert.strictEqual(typeof utils.compileETag('weak'), 'function'); + }); + + it('should throw for unknown string values', function () { + assert.throws(() => utils.compileETag('foo'), TypeError); + }); + + it('should throw for unsupported types like arrays and objects', function () { + assert.throws(() => utils.compileETag([]), TypeError); + assert.throws(() => utils.compileETag({}), TypeError); + }); + + });