From 19649407cbad1b45051b593870bd1804834628f8 Mon Sep 17 00:00:00 2001 From: Emelia Smith Date: Wed, 29 Jul 2020 03:20:41 +0200 Subject: [PATCH] test: improve coverage for subject max header length Previously specifying a custom max header width wasn't actually tested for, only the configuration loading was tested. This ensures that we have coverage on this functionality. --- engine.test.js | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/engine.test.js b/engine.test.js index 9ff66102..f73cd4c8 100644 --- a/engine.test.js +++ b/engine.test.js @@ -241,18 +241,42 @@ describe('commit message', function() { }); describe('validation', function() { - it('subject exceeds max length', function() { - expect(() => - commitMessage({ - type, - scope, - subject: longBody - }) - ).to.throw( - 'length must be less than or equal to ' + - `${defaultOptions.maxLineWidth - type.length - scope.length - 4}` - ); + describe('subject exceeds max length', function() { + it('using the default max length', function() { + expect(() => + commitMessage({ + type, + scope, + subject: longBody + }) + ).to.throw( + 'length must be less than or equal to ' + + `${defaultOptions.maxLineWidth - type.length - scope.length - 4}` + ); + }); + + it('using a custom max length', function() { + var customMaxHeaderWidth = 30; + + expect(() => + commitMessage( + { + type, + scope, + subject: longBody + }, + { + ...defaultOptions, + maxHeaderWidth: customMaxHeaderWidth + } + ) + ).to.throw( + 'length must be less than or equal to ' + + `${customMaxHeaderWidth - type.length - scope.length - 4}` + ); + }); }); + it('empty subject', function() { expect(() => commitMessage({