Skip to content

Commit 0dac764

Browse files
committed
chapter 03: using the fakeManagerExtension to fix the failed test from the previous commit
1 parent 108928e commit 0dac764

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('isValidLogFileName', () => {
3535
`(
3636
'when called there changes wasLastFileNameValid that returns $expected',
3737
({ fileName, expected }) => {
38-
console.log(fileName);
3938
logAnalyzerInstance.isValidLogFileName(fileName);
4039
const result = logAnalyzerInstance.getWasLastFileNameValid();
4140

chapter_03-using-stubs-to-break-dependencies/LogAn/logAnalyzer.test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const logAnalyzer = require('./logAnalyzer');
1+
const logAnalyzerFactory = require('./logAnalyzer');
2+
const fakeExtensionManagerFactory = require('./fakeExtensionManager');
3+
4+
let myFakeExtensionManager;
25

3-
let logAnalyzerInstance;
46
beforeEach(() => {
5-
logAnalyzerInstance = logAnalyzer();
7+
myFakeExtensionManager = fakeExtensionManagerFactory();
68
});
79

810
describe.each([
@@ -11,15 +13,20 @@ describe.each([
1113
['johndoe.SLF', true],
1214
])('isValidLogFileName("%s"))', (fileName, expected) => {
1315
it(`bad extension returns ${expected}`, async () => {
14-
const result = await logAnalyzerInstance.isValidLogFileName(fileName);
16+
myFakeExtensionManager.willBeValid(expected);
17+
18+
const logAnalyzer = logAnalyzerFactory(myFakeExtensionManager);
19+
const result = await logAnalyzer.isValidLogFileName(fileName);
1520
expect(result).toBe(expected);
1621
});
1722
});
1823

1924
describe('isValidLogFileName', () => {
2025
it('empty filename throws error', async () => {
2126
async function emptyLogFileName() {
22-
return logAnalyzerInstance.isValidLogFileName('');
27+
const logAnalyzer = logAnalyzerFactory(myFakeExtensionManager);
28+
29+
return logAnalyzer.isValidLogFileName('');
2330
}
2431

2532
await expect(emptyLogFileName()).rejects.toThrow(
@@ -37,8 +44,11 @@ describe('isValidLogFileName', () => {
3744
`(
3845
'when called there changes wasLastFileNameValid that returns $expected',
3946
async ({ fileName, expected }) => {
40-
await logAnalyzerInstance.isValidLogFileName(fileName);
41-
const result = logAnalyzerInstance.getWasLastFileNameValid();
47+
myFakeExtensionManager.willBeValid(expected);
48+
49+
const logAnalyzer = logAnalyzerFactory(myFakeExtensionManager);
50+
await logAnalyzer.isValidLogFileName(fileName);
51+
const result = logAnalyzer.getWasLastFileNameValid();
4252

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

0 commit comments

Comments
 (0)