10 examples of 'sinon stub restore' in JavaScript

Every line of 'sinon stub restore' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
25restore() {
26 if (this.useGlobalSandbox || this.useSandbox) {
27 this.instance.restore();
28 }
29}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

132restore ({ localStorage, sessionStorage }) {
133 this.localStorageWrapper.restore(localStorage);
134 this.sessionStorageWrapper.restore(sessionStorage);
135}
48restore() {
49 THREE.ShapeGeometry.prototype = this.oldPrototype;
50}
25const restore = function stubRestoreNodeModules() {
26 if (fs.existsSync(nodeModulesPath)) {
27 fs.removeSync(nodeModulesPath);
28 }
29};
119test(function restore() {
120 var OBJ = {}, NAME = '[my object].myFn()';
121 OBJ.foo = function(x) {
122 return x;
123 };
124
125 gently._name = function() {
126 return NAME;
127 };
128
129 var original = OBJ.foo;
130 gently.expect(OBJ, 'foo');
131 gently.restore(OBJ, 'foo');
132 assert.strictEqual(OBJ.foo, original);
133
134 (function testError() {
135 try {
136 gently.restore(OBJ, 'foo');
137 assert.ok(false, 'throw needs to happen');
138 } catch (e) {
139 assert.equal(e.message, NAME+' is not gently stubbed');
140 }
141 })();
142});
351sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
352 if (supportsXHR) {
353 global.XMLHttpRequest = GlobalXMLHttpRequest;
354 }
355
356 if (supportsActiveX) {
357 global.ActiveXObject = GlobalActiveXObject;
358 }
359
360 delete sinon.FakeXMLHttpRequest.restore;
361
362 if (keepOnCreate !== true) {
363 delete sinon.FakeXMLHttpRequest.onCreate;
364 }
365};
513sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
514 if (xhr.supportsXHR) {
515 global.XMLHttpRequest = xhr.GlobalXMLHttpRequest;
516 }
517
518 if (xhr.supportsActiveX) {
519 global.ActiveXObject = xhr.GlobalActiveXObject;
520 }
521
522 delete sinon.FakeXMLHttpRequest.restore;
523
524 if (keepOnCreate !== true) {
525 delete sinon.FakeXMLHttpRequest.onCreate;
526 }
527};
49export function stubMethod(obj, methodName, method) {
50 const test = current;
51 const prev = obj[methodName];
52
53 let called = false;
54 let callCount = 0;
55 let calls = [];
56 let restored = false;
57
58 obj[methodName] = function(...args) {
59 assertActive(test);
60 called = true;
61 callCount++;
62 calls.push({
63 context: this,
64 args: args
65 });
66 method.apply(this, args);
67 };
68
69 const stub = {};
70
71 defineGetter(test, stub, 'called', () => called);
72 defineGetter(test, stub, 'callCount', () => callCount);
73 defineGetter(test, stub, 'calls', () => calls);
74
75 function restore() {
76 if (!restored) {
77 obj[methodName] = prev;
78 restored = true;
79 }
80 }
81
82 stub.restore = () => {
83 assertActive(test);
84 restore();
85 };
86
87 restores.push(restore);
88
89 return stub;
90}
12restore: function restore() { if (this._handle) { this._handle.restore(); this._handle = null; } }
140function restoreStubs() {
141 for (const method of Object.keys(fakeCoap)) {
142 fakeCoap[method].restore();
143 }
144}

Related snippets