Skip to content

Commit

Permalink
chapter 03: testing the the new class using the technique Extract and…
Browse files Browse the repository at this point in the history
… Override
  • Loading branch information
devcorpio committed Jan 11, 2019
1 parent 3847482 commit 3d89553
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const logAnalyzerFactory = require('./logAnalyzer');
const fakeExtensionManagerFactory = require('./fakeExtensionManager');
const extensionManagerFactory = require('./extensionManager');

// imported to try the technique "Extract and override"
const TestableLogAnalyzerClass = require('./testableLogAnalyzer.class');

let myFakeExtensionManager;

beforeEach(() => {
Expand Down Expand Up @@ -83,4 +86,26 @@ describe('isValidLogFileName', () => {

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

/**
* I'm using the tecnique "Extract and override", this technique has several steps:
*
* step 1: create a virtual function in the unit under test(logAnalyzer.js in this case)
* that returns the real extension manager, the one that works with the filesystem
*
* step 2: create a class that extends of it
*
* step3: use this new class to create the tests!! :)
*/
it('return false using testableLogAnalyzer', async () => {
const expected = false;
myFakeExtensionManager.willBeValid(expected);

const logAnalyzer = new TestableLogAnalyzerClass(
myFakeExtensionManager
);
const result = await logAnalyzer.isValidLogFileName('johndoe.ts');

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

0 comments on commit 3d89553

Please sign in to comment.