I’m learning TDD (in Javascript), and I wanted to know, what is the right way to use configuration variables? Should I make a separate class and have them be member variables of the class, and pass an instance of the class to every object that needs it, or make a list of global variables and just use those? What are the benefits / setbacks of each method?
For example, I have to get data from a URL as follows:
function getData (remoteDataDelegate) {
remoteDataDelegate.getData(userInfoURL)
}
where userInfoURL is a configuration variable that I set elsewhere to the URL for a page on my site.
This is an example of how I do it:
Usage:
You will notice that the configuration is not being injected. for me, in this sample code the configuration never changes. Now my request objects change so they get injected, so I can mock those out or redirect the pages.