Skip to content

Commit

Permalink
chapter 02: add test that assert that the error is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
devcorpio committed Jan 9, 2019
1 parent 279aacc commit 7e50568
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 7e50568

Please sign in to comment.