From 7e50568fa812cdaaf0c8e48fb58d643979b85a52 Mon Sep 17 00:00:00 2001 From: devcorpio Date: Wed, 9 Jan 2019 13:16:38 +0100 Subject: [PATCH] chapter 02: add test that assert that the error is thrown --- .../LogAn/logAnalyzer.test.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js b/chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js index 16bea16..3e5702f 100644 --- a/chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js +++ b/chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js @@ -1,17 +1,27 @@ const logAnalyzer = require('./logAnalyzer'); +let logAnalyzerInstance; +beforeEach(() => { + logAnalyzerInstance = logAnalyzer(); +}); + describe.each([ ['johndoe.js', false], ['johndoe.slf', true], ['johndoe.SLF', true], ])('isValidLogFileName("%s"))', (fileName, expected) => { - let logAnalyzerInstance; - beforeEach(() => { - logAnalyzerInstance = logAnalyzer(); - }); - it(`bad extension returns ${expected}`, () => { const result = logAnalyzerInstance.isValidLogFileName(fileName); expect(result).toBe(expected); }); }); + +describe('isValidLogFileName', () => { + it('empty filename throws error', () => { + function emptyLogFileName() { + logAnalyzerInstance.isValidLogFileName(''); + } + + expect(emptyLogFileName).toThrow('filename has to be provided'); + }); +});