I want to stub process.env.FOO
with bar
.
var sinon = require(\'sinon\');
var stub = sinon.stub(process.env, \'FOO\', \'bar\');
<
In a spec-helper.coffee
or something similar where you set up your sinon sandbox, keep track of the original process.env
and restore it after each test, so you don't leak between tests and don't have to remember to reset every time.
_ = require 'lodash'
sinon = require 'sinon'
beforeEach ->
@originalProcessEnv = _.cloneDeep process.env
afterEach ->
process.env = _.cloneDeep @originalProcessEnv
In your test, use process.env
as normal.
it 'does something based on an env var', ->
process.env.FOO = 'bar'