Created
February 23, 2021 02:05
-
-
Save brainysmurf/ff3b2c5e4284cb6730c77c91aff7c269 to your computer and use it in GitHub Desktop.
Illustrating how one can orchestrate mocks using dependency injection
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
function work_ (url, {UrlFetchApp_=UrlFetchApp}={}) { | |
Logger.log(url); | |
return UrlFetchApp_.fetch(url).getContentText(); | |
} | |
function testWork() { | |
const url = 'https://example.com'; | |
const response1 = work_(url); | |
Logger.log(response1); | |
class Mocked { | |
static fetch() { | |
return { | |
getContentText: () => 'ha' | |
}; | |
} | |
} | |
const response2 = work_(url, {UrlFetchApp_: Mocked}); | |
Logger.log(response2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment