Created
October 13, 2018 18:18
-
-
Save JustinDFuller/ad6218cac91c543d9de50d30cd57340f to your computer and use it in GitHub Desktop.
Dependency Inversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is my file I'll be testing foo.js */ | |
export default function ({ readFileAsync }) { | |
return { | |
readJsonFile (filePath) { | |
return readFileAsync(filePath).then(JSON.parse) | |
} | |
} | |
} | |
/* This is my test file foo.test.js */ | |
import test from 'ava' | |
import foo from './foo' | |
test('foo with dependency inversion', function (t) { | |
t.plan(2) | |
const dependencies = { | |
readFileAsync(filePath) { | |
t.is(filePath, 'bar') | |
return Promise.resolve('{ success: true '}) | |
} | |
} | |
const result = await foo(dependencies).readJsonFile('bar') | |
t.deepEqual(result, { success: true }) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment