-
-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property stubbing on process.env in node throws #188
Comments
➜ /tmp npm install [email protected]
...
➜ /tmp node
> require("sinon").sandbox.create().stub(process.env, "PATH", "meh");
{ restore: [Function] } |
So I can start measuring your response time with high resolution timers? |
Hehe. I was stuck and tired and figured I might as well fix this issue instead :) |
Hmm, I guess this doesn't work anymore?
I've spent a while trying to find an alternative way to stub |
Use a sandbox. That's the only supported way to stub a property. -Max
|
I use a sandbox and also run into issues. To explain this: I require my AWS key and secret to be in my ENV vars. I have a function that tells me when a any of them are missing. So I want to set the describe('when I need the missing keys in the ENV vars', () => {
let sandbox;
beforeEach(() => { sandbox = sinon.sandbox.create(); });
afterEach(() => { sandbox.restore(); });
it('should return the key/value pair if AWS_ACCESS_KEY_ID is missing', () => {
sandbox.stub(process.env, 'AWS_SECRET_ACCESS_KEY', 'some access key');
S3Client.getMissingKeysInEnv().length.should.equal(1);
// other assertions
});
}); what I get is
|
Workaround is stubbing the whole environment, like: describe('when I need the missing keys in the ENV vars', () => {
const sandbox = sinon.sandbox.create();
afterEach(() => sandbox.restore());
it('should have mocked environment', () => {
sandbox.stub(process, 'env', {SOME_KEY: 'some value'});
});
}); |
Since version 3 I can't get it to work, could you shed some light on this @cjohansen? |
process.env
does not implementhasOwnProperty
.Reproduce on the node repl:
Interestingly, stubbing the entire environment works.
The text was updated successfully, but these errors were encountered: