Skip to content

Commit 305fb6c

Browse files
mroderickfearphage
andauthored
fix: actaully reset 'injectedKeys' (#2456)
* refactor: Remove single-use variable * fix: actaully reset 'injectedKeys' Re-assigning the local variable `injectedKeys` would not change `sandbox.injectedKeys`, thus `restoreContext` doesn't fully restore the context. See: https://lgtm.com/projects/g/sinonjs/sinon/snapshot/9e09e7d79bac5808ca98fac4f7419a20be4fc43d/files/lib/sinon/sandbox.js?sort=name&dir=ASC&mode=heatmap#x9f770d565ef51b7d:1 * Update lib/sinon/sandbox.js Co-authored-by: Phred Lane <[email protected]> --------- Co-authored-by: Phred Lane <[email protected]>
1 parent 8186280 commit 305fb6c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Diff for: lib/sinon/sandbox.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,15 @@ function Sandbox() {
197197
};
198198

199199
sandbox.restoreContext = function restoreContext() {
200-
let injectedKeys = sandbox.injectedKeys;
201-
const injectInto = sandbox.injectInto;
202-
203-
if (!injectedKeys) {
200+
if (!sandbox.injectedKeys) {
204201
return;
205202
}
206203

207-
forEach(injectedKeys, function (injectedKey) {
208-
delete injectInto[injectedKey];
204+
forEach(sandbox.injectedKeys, function (injectedKey) {
205+
delete sandbox.injectInto[injectedKey];
209206
});
210207

211-
injectedKeys = [];
208+
sandbox.injectedKeys.length = 0;
212209
};
213210

214211
function getFakeRestorer(object, property) {

0 commit comments

Comments
 (0)