Skip to content

Commit

Permalink
chapter 02: first state-based test for logAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
devcorpio committed Jan 9, 2019
1 parent 0900685 commit 8d21eb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chapter_02-a-first-unit-test/LogAn/logAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function logAnalyzer() {
/**
* @return {boolean}
*/
function getWasLastFilenameValid() {
function getWasLastFileNameValid() {
return wasLastFileNameValid;
}

Expand All @@ -33,7 +33,7 @@ function logAnalyzer() {
}

return {
getWasLastFilenameValid,
getWasLastFileNameValid,
isValidLogFileName,
};
}
Expand Down
18 changes: 18 additions & 0 deletions chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ describe('isValidLogFileName', () => {

expect(emptyLogFileName).toThrow('filename has to be provided');
});

/**
* an example of state-based testing
*/
it.each`
fileName | expected
${'johndoe.foo'} | ${false}
${'johndoe.slf'} | ${true}
`(
'when called there changes wasLastFileNameValid that returns $expected',
({ fileName, expected }) => {
console.log(fileName);
logAnalyzerInstance.isValidLogFileName(fileName);
const result = logAnalyzerInstance.getWasLastFileNameValid();

expect(result).toBe(expected);
}
);
});

0 comments on commit 8d21eb8

Please sign in to comment.