Skip to content

Commit baecfdc

Browse files
committed
chapter 03: using extensionManagerFactory I created an unit test, because the test is making use of a fake extension manager, therefore I'm not using the filesystem that is an external dependency
1 parent ceb8d02 commit baecfdc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,20 @@ describe('isValidLogFileName', () => {
6767

6868
expect(result).toBe(true);
6969
});
70+
71+
/**
72+
* an example of use of "injecting a fake just before a method call"
73+
* In this case I'm setting a fake extension manager, that converts this in a unit test!!, because
74+
* right now I have not external dependencies.
75+
*/
76+
it('return true using extensionManagerFactory', async () => {
77+
myFakeExtensionManager.willBeValid(true);
78+
const extensionManager = extensionManagerFactory();
79+
extensionManager.setManager(myFakeExtensionManager);
80+
81+
const logAnalyzer = logAnalyzerFactory(extensionManager.create());
82+
const result = await logAnalyzer.isValidLogFileName('johndoe.sql');
83+
84+
expect(result).toBe(true);
85+
});
7086
});

0 commit comments

Comments
 (0)