Created
March 24, 2017 02:14
-
-
Save morrissinger/9a892edbf41d4544bc25a7a92dced6ef to your computer and use it in GitHub Desktop.
Dependency inversion in JavaScript with Curry
This file contains hidden or 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
| // Import actual dependencies | |
| const dependency1 = require('dependency1'), | |
| dependency2 = require('dependency2'); | |
| const myExport = require('./my-export.js')(dependency1, dependency2); | |
| /* Do something */ |
This file contains hidden or 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
| const curry = require('lodash').curry; | |
| const export = curry((dependency1, dependency2, arg1, arg2, arg3) => { | |
| /* Do something */ | |
| }); | |
| module.exports = (dependency1, dependency2) => { | |
| export: export(dependency1, dependency2) | |
| } |
This file contains hidden or 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
| // Import mocks, collections of stubs, spies, etc. | |
| const dependency1 = require('mocks/dependency1'), | |
| dependency2 = require('mocks/dependency2'); | |
| const myExport = require('./my-export'); | |
| describe('my export', function () { | |
| let subject; | |
| beforeEach(function (done) { | |
| subject = myExport(dependency1, dependency2); | |
| done(); | |
| }); | |
| it('does something', function (done) { | |
| /* Test something */ | |
| done(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment