How to stub process.env in node.js?
问题 I want to stub process.env.FOO with bar . var sinon = require('sinon'); var stub = sinon.stub(process.env, 'FOO', 'bar'); I'm confused. I read document, but still I don't understand yet.sinonjs docs sinonjs is one example, not sinonjs is okay. 回答1: From my understanding of process.env , you can simply treat it like any other variable when setting its properties. Keep in mind, though, that every value in process.env must be a string. So, if you need a particular value in your test: it('does