Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
atMost: function atMost(num) {
if (typeof num !== "number") {
throw new TypeError("'" + valueToString(num) + "' is not number");
}
if (!this.limitsSet) {
this.minCalls = null;
this.limitsSet = true;
}
this.maxCalls = num;
return this;
},
function getCallbackError(behavior, func, args) {
if (behavior.callArgAt < 0) {
var msg;
if (behavior.callArgProp) {
msg =
functionName(behavior.stub) +
" expected to yield to '" +
valueToString(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
}
if (args.length > 0) {
msg += " Received [" + join(args, ", ") + "]";
}
return msg;
}
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
}
function match(expectation, message) {
var m = Object.create(matcher);
var type = typeOf(expectation);
if (type in TYPE_MAP) {
TYPE_MAP[type](m, expectation, message);
} else {
m.test = function (actual) {
return deepEqual(expectation, actual);
};
}
if (!m.message) {
m.message = "match(" + valueToString(expectation) + ")";
}
return m;
}
match.in = function(arrayOfExpectations) {
if (typeOf(arrayOfExpectations) !== "array") {
throw new TypeError("array expected");
}
return match(function(actual) {
return some(arrayOfExpectations, function(expectation) {
return expectation === actual;
});
}, "in(" + valueToString(arrayOfExpectations) + ")");
};
}
var isActualDate = isDate(actualObj);
var isExpectationDate = isDate(expectationObj);
if (isActualDate || isExpectationDate) {
if (
!isActualDate ||
!isExpectationDate ||
getTime.call(actualObj) !== getTime.call(expectationObj)
) {
return false;
}
}
if (actualObj instanceof RegExp && expectationObj instanceof RegExp) {
if (valueToString(actualObj) !== valueToString(expectationObj)) {
return false;
}
}
if (actualObj instanceof Error && expectationObj instanceof Error) {
return actualObj === expectationObj;
}
var actualClass = getClass(actualObj);
var expectationClass = getClass(expectationObj);
var actualKeys = keys(actualObj);
var expectationKeys = keys(expectationObj);
var actualName = className(actualObj);
var expectationName = className(expectationObj);
var expectationSymbols =
typeof getOwnPropertySymbols === "function"
function getCallbackError(behavior, func, args) {
if (behavior.callArgAt < 0) {
var msg;
if (behavior.callArgProp) {
msg =
functionName(behavior.stub) +
" expected to yield to '" +
valueToString(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
}
if (args.length > 0) {
msg += " Received [" + join(args, ", ") + "]";
}
return msg;
}
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
}
array = map(Object.keys(expectation), function (key) {
return key + ": " + valueToString(expectation[key]);
});
function checkWrappedMethod(wrappedMethod) {
var error;
if (!isFunction(wrappedMethod)) {
error = new TypeError(
"Attempted to wrap " + typeof wrappedMethod + " property " + valueToString(property) + " as function"
);
} else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already wrapped");
} else if (wrappedMethod.calledBefore) {
var verb = wrappedMethod.returns ? "stubbed" : "spied on";
error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already " + verb);
}
if (error) {
if (wrappedMethod && wrappedMethod.stackTraceError) {
error.stack += "\n--------------\n" + wrappedMethod.stackTraceError.stack;
}
throw error;
}
}
sandbox.replace = function replace(object, property, replacement) {
var descriptor = getPropertyDescriptor(object, property);
if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
}
if (typeof replacement === "undefined") {
throw new TypeError("Expected replacement argument to be defined");
}
if (typeof descriptor.get === "function") {
throw new Error("Use sandbox.replaceGetter for replacing getters");
}
if (typeof descriptor.set === "function") {
throw new Error("Use sandbox.replaceSetter for replacing setters");
}
if (typeof object[property] !== typeof replacement) {
throw new TypeError("Cannot replace " + typeof object[property] + " with " + typeof replacement);
function getCallbackError(behavior, func, args) {
if (behavior.callArgAt < 0) {
var msg;
if (behavior.callArgProp) {
msg =
functionName(behavior.stub) +
" expected to yield to '" +
valueToString(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
}
if (args.length > 0) {
msg += " Received [" + join(args, ", ") + "]";
}
return msg;
}
return "argument at index " + behavior.callArgAt + " is not a function: " + func;
}