Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Mocking runtime config value with sinon

$
0
0

I am adding some config values before hapi server start. Application is works fine although in test I can not use config.get(). I can get around with proxyquire. So I was wondering

  • Is adding config file "dynamically" is bad design?
  • Is there a way I can use config.get() in such suitation?
  • Any alternative approach?

    //initialize.jsconst config = require('config');async function startServe() {  const someConfigVal = await callAPIToGetSomeJSONObject();  config.dynamicValue = someConfigVal;  server.start(); }//doSomething.jsconst config = require('config');function doesWork() {  const valFromConfig = config.dynamicValue.X;  // In test I can use proxiquire by creating config object  ...}function doesNotWork() {  const valFromConfig = config.get('dynamicValue.X');   // Does not work with sinon mocking as this value does not exist in config when test run.  // sinon.stub(config, 'get').withArgs('dynamicValue.X').returns(someVal);  .....}

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>