test process.env with Jest

后端 未结 9 1946
南笙
南笙 2020-11-28 04:00

I have an app that depends on environmental variables like:

const APP_PORT = process.env.APP_PORT || 8080;

and I would like to test that fo

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 04:15

    In ./package.json:

    "jest": {
      "setupFiles": [
        "/jest/setEnvVars.js"
      ]
    }
    

    In ./jest/setEnvVars.js:

    process.env.SOME_VAR = 'value';
    
    

提交回复
热议问题