Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createSpy(func) {
var name;
var funk = func;
if (typeof funk !== "function") {
funk = function() {
return;
};
} else {
name = functionName(funk);
}
var proxy = createProxy(funk, funk);
// Inherit spy API:
extend.nonEnum(proxy, spyApi);
extend.nonEnum(proxy, {
displayName: name || "spy",
fakes: [],
instantiateFake: createSpy,
id: "spy#" + uuid++
});
return proxy;
}
var fnStub =
pop(
sort(matchings, function(a, b) {
return a.matchingArguments.length - b.matchingArguments.length;
})
) || proxy;
return getCurrentBehavior(fnStub).invoke(this, arguments);
}
proxy = createProxy(functionStub, originalFunc || functionStub);
// Inherit spy API:
extend.nonEnum(proxy, spy);
// Inherit stub API:
extend.nonEnum(proxy, stub);
var name = originalFunc ? functionName(originalFunc) : null;
extend.nonEnum(proxy, {
fakes: [],
instantiateFake: createStub,
displayName: name || "stub",
defaultBehavior: null,
behaviors: [],
id: "stub#" + uuid++
});
return proxy;
}
var fnStub =
pop(
sort(matchings, function(a, b) {
return a.matchingArguments.length - b.matchingArguments.length;
})
) || proxy;
return getCurrentBehavior(fnStub).invoke(this, arguments);
}
proxy = createProxy(functionStub, originalFunc || functionStub);
// Inherit spy API:
extend.nonEnum(proxy, spy);
// Inherit stub API:
extend.nonEnum(proxy, stub);
var name = originalFunc ? functionName(originalFunc) : null;
extend.nonEnum(proxy, {
fakes: [],
instantiateFake: createStub,
displayName: name || "stub",
defaultBehavior: null,
behaviors: [],
id: "stub#" + uuid++
});
return proxy;
}
function constructorName(f, object) {
var name = functionName(object && object.constructor);
var excludes = f.excludeConstructors || formatio.excludeConstructors;
var i, l;
for (i = 0, l = excludes.length; i < l; ++i) {
if (typeof excludes[i] === "string" && excludes[i] === name) {
return "";
} else if (excludes[i].test && excludes[i].test(name)) {
return "";
}
}
return name;
}
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 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: function(m, expectation, message) {
m.test = expectation;
m.message = message || "match(" + functionName(expectation) + ")";
},
number: function(m, expectation) {
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;
}