Skip to content

Commit 8d21eb8

Browse files
committed
chapter 02: first state-based test for logAnalyzer
1 parent 0900685 commit 8d21eb8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

chapter_02-a-first-unit-test/LogAn/logAnalyzer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function logAnalyzer() {
99
/**
1010
* @return {boolean}
1111
*/
12-
function getWasLastFilenameValid() {
12+
function getWasLastFileNameValid() {
1313
return wasLastFileNameValid;
1414
}
1515

@@ -33,7 +33,7 @@ function logAnalyzer() {
3333
}
3434

3535
return {
36-
getWasLastFilenameValid,
36+
getWasLastFileNameValid,
3737
isValidLogFileName,
3838
};
3939
}

chapter_02-a-first-unit-test/LogAn/logAnalyzer.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,22 @@ describe('isValidLogFileName', () => {
2424

2525
expect(emptyLogFileName).toThrow('filename has to be provided');
2626
});
27+
28+
/**
29+
* an example of state-based testing
30+
*/
31+
it.each`
32+
fileName | expected
33+
${'johndoe.foo'} | ${false}
34+
${'johndoe.slf'} | ${true}
35+
`(
36+
'when called there changes wasLastFileNameValid that returns $expected',
37+
({ fileName, expected }) => {
38+
console.log(fileName);
39+
logAnalyzerInstance.isValidLogFileName(fileName);
40+
const result = logAnalyzerInstance.getWasLastFileNameValid();
41+
42+
expect(result).toBe(expected);
43+
}
44+
);
2745
});

0 commit comments

Comments
 (0)