Skip to content

Commit

Permalink
fix: should check process.env
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Jun 12, 2016
1 parent 7de27b7 commit 1cefede
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ var method = module.exports = function mockMethod(obj, key, method) {
delete obj[key];
}

// set a flag that checks if it is mocked
var flag = cache.get(obj);
if (!flag) {
flag = new Set();
cache.set(obj, flag);
}
flag.add(key);

// Can't not delete the property of process.env before node@4
if (obj === process.env) {
obj[key] = method;
Expand All @@ -41,13 +49,6 @@ var method = module.exports = function mockMethod(obj, key, method) {
value: method
});

// set a flag that checks if it is mocked
var flag = cache.get(obj);
if (!flag) {
flag = new Set();
cache.set(obj, flag);
}
flag.add(key);
};

/**
Expand Down
6 changes: 6 additions & 0 deletions test/method-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ describe('Mock check', function() {
muk(obj, 'e', 2);
assert.ok(muk.isMocked(obj, 'e'));
});

it('should check process.env', function() {
muk(process.env, 'HOME', '/mockhome');
assert.equal(process.env.HOME, '/mockhome');
assert.ok(muk.isMocked(process.env, 'HOME'));
});
});

function hasOwnProperty(obj, prop) {
Expand Down

0 comments on commit 1cefede

Please sign in to comment.