Comparing version 15.2.0 to 16.0.0
@@ -18,3 +18,5 @@ "use strict"; | ||
fake.exceptionCreator = function () { | ||
const newException = new Error(message || ""); | ||
const newException = new Error( | ||
message || `Sinon-provided ${error}` | ||
); | ||
newException.name = error; | ||
@@ -21,0 +23,0 @@ return newException; |
@@ -109,2 +109,6 @@ "use strict"; | ||
obj.define = function () { | ||
return sandbox.define.apply(null, arguments); | ||
}; | ||
obj.replace = function () { | ||
@@ -162,19 +166,3 @@ return sandbox.replace.apply(null, arguments); | ||
forEach(collection, function (fake) { | ||
if (typeof fake === "function") { | ||
privateResetHistory(fake); | ||
return; | ||
} | ||
const methods = []; | ||
if (fake.get) { | ||
push(methods, fake.get); | ||
} | ||
if (fake.set) { | ||
push(methods, fake.set); | ||
} | ||
forEach(methods, privateResetHistory); | ||
}); | ||
forEach(collection, privateResetHistory); | ||
}; | ||
@@ -202,14 +190,11 @@ | ||
sandbox.restoreContext = function restoreContext() { | ||
let injectedKeys = sandbox.injectedKeys; | ||
const injectInto = sandbox.injectInto; | ||
if (!injectedKeys) { | ||
if (!sandbox.injectedKeys) { | ||
return; | ||
} | ||
forEach(injectedKeys, function (injectedKey) { | ||
delete injectInto[injectedKey]; | ||
forEach(sandbox.injectedKeys, function (injectedKey) { | ||
delete sandbox.injectInto[injectedKey]; | ||
}); | ||
injectedKeys = []; | ||
sandbox.injectedKeys.length = 0; | ||
}; | ||
@@ -221,3 +206,3 @@ | ||
function restorer() { | ||
if (descriptor.isOwn) { | ||
if (descriptor?.isOwn) { | ||
Object.defineProperty(object, property, descriptor); | ||
@@ -228,2 +213,3 @@ } else { | ||
} | ||
restorer.object = object; | ||
@@ -254,3 +240,3 @@ restorer.property = property; | ||
property | ||
)}` | ||
)}. Perhaps you meant sandbox.define()?` | ||
); | ||
@@ -289,2 +275,27 @@ } | ||
sandbox.define = function define(object, property, value) { | ||
const descriptor = getPropertyDescriptor(object, property); | ||
if (descriptor) { | ||
throw new TypeError( | ||
`Cannot define the already existing property ${valueToString( | ||
property | ||
)}. Perhaps you meant sandbox.replace()?` | ||
); | ||
} | ||
if (typeof value === "undefined") { | ||
throw new TypeError("Expected value argument to be defined"); | ||
} | ||
verifyNotReplaced(object, property); | ||
// store a function for restoring the defined property | ||
push(fakeRestorers, getFakeRestorer(object, property)); | ||
object[property] = value; | ||
return value; | ||
}; | ||
sandbox.replaceGetter = function replaceGetter( | ||
@@ -368,4 +379,3 @@ object, | ||
function commonPostInitSetup(args, spy) { | ||
const object = args[0]; | ||
const property = args[1]; | ||
const [object, property, types] = args; | ||
@@ -383,2 +393,7 @@ const isSpyingOnEntireObject = | ||
usePromiseLibrary(promiseLib, ownMethods); | ||
} else if (Array.isArray(types)) { | ||
for (const accessorType of types) { | ||
addToCollection(spy[accessorType]); | ||
usePromiseLibrary(promiseLib, spy[accessorType]); | ||
} | ||
} else { | ||
@@ -385,0 +400,0 @@ addToCollection(spy); |
@@ -13,2 +13,3 @@ "use strict"; | ||
"fake", | ||
"define", | ||
"replace", | ||
@@ -15,0 +16,0 @@ "replaceSetter", |
"use strict"; | ||
module.exports = function getPropertyDescriptor(object, property) { | ||
/* eslint-disable jsdoc/valid-types */ | ||
/* | ||
* The following type def is strictly an illegal JSDoc, but the expression forms a | ||
* legal Typescript union type and is understood by Visual Studio and the IntelliJ | ||
* family of editors. The "TS" flavor of JSDoc is becoming the de-facto standard these | ||
* days for that reason (and the fact that JSDoc is essentially unmaintained) | ||
*/ | ||
/** | ||
* @typedef {{isOwn: boolean} & PropertyDescriptor} SinonPropertyDescriptor | ||
* a slightly enriched property descriptor | ||
* @property {boolean} isOwn true if the descriptor is owned by this object, false if it comes from the prototype | ||
*/ | ||
/* eslint-enable jsdoc/valid-types */ | ||
/** | ||
* Returns a slightly modified property descriptor that one can tell is from the object or the prototype | ||
* | ||
* @param {*} object | ||
* @param {string} property | ||
* @returns {SinonPropertyDescriptor} | ||
*/ | ||
function getPropertyDescriptor(object, property) { | ||
let proto = object; | ||
@@ -22,2 +44,4 @@ let descriptor; | ||
return descriptor; | ||
}; | ||
} | ||
module.exports = getPropertyDescriptor; |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "15.2.0", | ||
"version": "16.0.0", | ||
"homepage": "https://sinonjs.org/", | ||
@@ -21,0 +21,0 @@ "author": "Christian Johansen", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4917069
62053