Socket
Socket
Sign inDemoInstall

sinon

Package Overview
Dependencies
Maintainers
2
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

lib/sinon/call.js

24

lib/sinon.js

@@ -52,2 +52,6 @@ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/

function isRestorable (obj) {
return typeof obj === "function" && typeof obj.restore === "function" && obj.restore.sinon;
}
var sinon = {

@@ -179,7 +183,3 @@ wrapMethod: function wrapMethod(object, property, method) {

if (aLength != bLength) {
return false;
}
return true;
return aLength == bLength;
},

@@ -304,2 +304,15 @@

return sinon.stub(sinon.create(constructor.prototype));
},
restore: function (object) {
if (object !== null && typeof object === "object") {
for (var prop in object) {
if (isRestorable(object[prop])) {
object[prop].restore();
}
}
}
else if (isRestorable(object)) {
object.restore();
}
}

@@ -316,2 +329,3 @@ };

module.exports.spy = require("./sinon/spy");
module.exports.spyCall = require("./sinon/call");
module.exports.stub = require("./sinon/stub");

@@ -318,0 +332,0 @@ module.exports.mock = require("./sinon/mock");

@@ -107,3 +107,10 @@ /**

expected = [].join.call(arguments, ", ");
actual = sinon.orderByFirstCall(slice.call(arguments)).join(", ");
var calls = slice.call(arguments);
var i = calls.length;
while (i) {
if (!calls[--i].called) {
calls.splice(i, 1);
}
}
actual = sinon.orderByFirstCall(calls).join(", ");
} catch (e) {

@@ -177,2 +184,2 @@ // If this fails, we'll just fall back to the blank string

}
}(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : global));
}(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global));
/**
* @depend ../sinon.js
* @depend match.js
* @depend call.js
*/

@@ -19,6 +19,5 @@ /*jslint eqeqeq: false, onevar: false, plusplus: false*/

var commonJSModule = typeof module == "object" && typeof require == "function";
var spyCall;
var push = Array.prototype.push;
var slice = Array.prototype.slice;
var callId = 0;
var push = [].push;
var slice = Array.prototype.slice;

@@ -46,520 +45,344 @@ if (!sinon && commonJSModule) {

sinon.extend(spy, (function () {
function matchingFake(fakes, args, strict) {
if (!fakes) {
return;
}
function delegateToCalls(api, method, matchAny, actual, notCalled) {
api[method] = function () {
if (!this.called) {
if (notCalled) {
return notCalled.apply(this, arguments);
}
return false;
}
var alen = args.length;
var currentCall;
var matches = 0;
for (var i = 0, l = fakes.length; i < l; i++) {
if (fakes[i].matches(args, strict)) {
return fakes[i];
}
}
}
for (var i = 0, l = this.callCount; i < l; i += 1) {
currentCall = this.getCall(i);
function incrementCallCount() {
this.called = true;
this.callCount += 1;
this.notCalled = false;
this.calledOnce = this.callCount == 1;
this.calledTwice = this.callCount == 2;
this.calledThrice = this.callCount == 3;
}
if (currentCall[actual || method].apply(currentCall, arguments)) {
matches += 1;
function createCallProperties() {
this.firstCall = this.getCall(0);
this.secondCall = this.getCall(1);
this.thirdCall = this.getCall(2);
this.lastCall = this.getCall(this.callCount - 1);
}
if (matchAny) {
return true;
}
}
}
return matches === this.callCount;
var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
function createProxy(func) {
// Retain the function length:
var p;
if (func.length) {
eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) +
") { return p.invoke(func, this, slice.call(arguments)); });");
}
else {
p = function proxy() {
return p.invoke(func, this, slice.call(arguments));
};
}
return p;
}
function matchingFake(fakes, args, strict) {
if (!fakes) {
return;
}
var uuid = 0;
var alen = args.length;
for (var i = 0, l = fakes.length; i < l; i++) {
if (fakes[i].matches(args, strict)) {
return fakes[i];
// Public API
var spyApi = {
reset: function () {
this.called = false;
this.notCalled = true;
this.calledOnce = false;
this.calledTwice = false;
this.calledThrice = false;
this.callCount = 0;
this.firstCall = null;
this.secondCall = null;
this.thirdCall = null;
this.lastCall = null;
this.args = [];
this.returnValues = [];
this.thisValues = [];
this.exceptions = [];
this.callIds = [];
if (this.fakes) {
for (var i = 0; i < this.fakes.length; i++) {
this.fakes[i].reset();
}
}
}
},
function incrementCallCount() {
this.called = true;
this.callCount += 1;
this.notCalled = false;
this.calledOnce = this.callCount == 1;
this.calledTwice = this.callCount == 2;
this.calledThrice = this.callCount == 3;
}
create: function create(func) {
var name;
function createCallProperties() {
this.firstCall = this.getCall(0);
this.secondCall = this.getCall(1);
this.thirdCall = this.getCall(2);
this.lastCall = this.getCall(this.callCount - 1);
}
var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
function createProxy(func) {
// Retain the function length:
var p;
if (func.length) {
eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) +
") { return p.invoke(func, this, slice.call(arguments)); });");
if (typeof func != "function") {
func = function () { };
} else {
name = sinon.functionName(func);
}
else {
p = function proxy() {
return p.invoke(func, this, slice.call(arguments));
};
}
return p;
}
var uuid = 0;
var proxy = createProxy(func);
// Public API
var spyApi = {
reset: function () {
this.called = false;
this.notCalled = true;
this.calledOnce = false;
this.calledTwice = false;
this.calledThrice = false;
this.callCount = 0;
this.firstCall = null;
this.secondCall = null;
this.thirdCall = null;
this.lastCall = null;
this.args = [];
this.returnValues = [];
this.thisValues = [];
this.exceptions = [];
this.callIds = [];
if (this.fakes) {
for (var i = 0; i < this.fakes.length; i++) {
this.fakes[i].reset();
}
}
},
sinon.extend(proxy, spy);
delete proxy.create;
sinon.extend(proxy, func);
create: function create(func) {
var name;
proxy.reset();
proxy.prototype = func.prototype;
proxy.displayName = name || "spy";
proxy.toString = sinon.functionToString;
proxy._create = sinon.spy.create;
proxy.id = "spy#" + uuid++;
if (typeof func != "function") {
func = function () { };
} else {
name = sinon.functionName(func);
}
return proxy;
},
var proxy = createProxy(func);
invoke: function invoke(func, thisValue, args) {
var matching = matchingFake(this.fakes, args);
var exception, returnValue;
sinon.extend(proxy, spy);
delete proxy.create;
sinon.extend(proxy, func);
incrementCallCount.call(this);
push.call(this.thisValues, thisValue);
push.call(this.args, args);
push.call(this.callIds, callId++);
proxy.reset();
proxy.prototype = func.prototype;
proxy.displayName = name || "spy";
proxy.toString = sinon.functionToString;
proxy._create = sinon.spy.create;
proxy.id = "spy#" + uuid++;
return proxy;
},
invoke: function invoke(func, thisValue, args) {
var matching = matchingFake(this.fakes, args);
var exception, returnValue;
incrementCallCount.call(this);
push.call(this.thisValues, thisValue);
push.call(this.args, args);
push.call(this.callIds, callId++);
try {
if (matching) {
returnValue = matching.invoke(func, thisValue, args);
} else {
returnValue = (this.func || func).apply(thisValue, args);
}
} catch (e) {
push.call(this.returnValues, undefined);
exception = e;
throw e;
} finally {
push.call(this.exceptions, exception);
}
push.call(this.returnValues, returnValue);
createCallProperties.call(this);
return returnValue;
},
getCall: function getCall(i) {
if (i < 0 || i >= this.callCount) {
return null;
}
return spyCall.create(this, this.thisValues[i], this.args[i],
this.returnValues[i], this.exceptions[i],
this.callIds[i]);
},
calledBefore: function calledBefore(spyFn) {
if (!this.called) {
return false;
}
if (!spyFn.called) {
return true;
}
return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
},
calledAfter: function calledAfter(spyFn) {
if (!this.called || !spyFn.called) {
return false;
}
return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1];
},
withArgs: function () {
var args = slice.call(arguments);
if (this.fakes) {
var match = matchingFake(this.fakes, args, true);
if (match) {
return match;
}
try {
if (matching) {
returnValue = matching.invoke(func, thisValue, args);
} else {
this.fakes = [];
returnValue = (this.func || func).apply(thisValue, args);
}
} catch (e) {
push.call(this.returnValues, undefined);
exception = e;
throw e;
} finally {
push.call(this.exceptions, exception);
}
var original = this;
var fake = this._create();
fake.matchingAguments = args;
push.call(this.fakes, fake);
push.call(this.returnValues, returnValue);
fake.withArgs = function () {
return original.withArgs.apply(original, arguments);
};
createCallProperties.call(this);
for (var i = 0; i < this.args.length; i++) {
if (fake.matches(this.args[i])) {
incrementCallCount.call(fake);
push.call(fake.thisValues, this.thisValues[i]);
push.call(fake.args, this.args[i]);
push.call(fake.returnValues, this.returnValues[i]);
push.call(fake.exceptions, this.exceptions[i]);
push.call(fake.callIds, this.callIds[i]);
}
}
createCallProperties.call(fake);
return returnValue;
},
return fake;
},
getCall: function getCall(i) {
if (i < 0 || i >= this.callCount) {
return null;
}
matches: function (args, strict) {
var margs = this.matchingAguments;
return sinon.spyCall(this, this.thisValues[i], this.args[i],
this.returnValues[i], this.exceptions[i],
this.callIds[i]);
},
if (margs.length <= args.length &&
sinon.deepEqual(margs, args.slice(0, margs.length))) {
return !strict || margs.length == args.length;
}
},
calledBefore: function calledBefore(spyFn) {
if (!this.called) {
return false;
}
printf: function (format) {
var spy = this;
var args = slice.call(arguments, 1);
var formatter;
if (!spyFn.called) {
return true;
}
return (format || "").replace(/%(.)/g, function (match, specifyer) {
formatter = spyApi.formatters[specifyer];
return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
},
if (typeof formatter == "function") {
return formatter.call(null, spy, args);
} else if (!isNaN(parseInt(specifyer), 10)) {
return sinon.format(args[specifyer - 1]);
}
return "%" + specifyer;
});
calledAfter: function calledAfter(spyFn) {
if (!this.called || !spyFn.called) {
return false;
}
};
delegateToCalls(spyApi, "calledOn", true);
delegateToCalls(spyApi, "alwaysCalledOn", false, "calledOn");
delegateToCalls(spyApi, "calledWith", true);
delegateToCalls(spyApi, "calledWithMatch", true);
delegateToCalls(spyApi, "alwaysCalledWith", false, "calledWith");
delegateToCalls(spyApi, "alwaysCalledWithMatch", false, "calledWithMatch");
delegateToCalls(spyApi, "calledWithExactly", true);
delegateToCalls(spyApi, "alwaysCalledWithExactly", false, "calledWithExactly");
delegateToCalls(spyApi, "neverCalledWith", false, "notCalledWith",
function () { return true; });
delegateToCalls(spyApi, "neverCalledWithMatch", false, "notCalledWithMatch",
function () { return true; });
delegateToCalls(spyApi, "threw", true);
delegateToCalls(spyApi, "alwaysThrew", false, "threw");
delegateToCalls(spyApi, "returned", true);
delegateToCalls(spyApi, "alwaysReturned", false, "returned");
delegateToCalls(spyApi, "calledWithNew", true);
delegateToCalls(spyApi, "alwaysCalledWithNew", false, "calledWithNew");
delegateToCalls(spyApi, "callArg", false, "callArgWith", function () {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgWith = spyApi.callArg;
delegateToCalls(spyApi, "callArgOn", false, "callArgOnWith", function () {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgOnWith = spyApi.callArgOn;
delegateToCalls(spyApi, "yield", false, "yield", function () {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
// "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
spyApi.invokeCallback = spyApi.yield;
delegateToCalls(spyApi, "yieldOn", false, "yieldOn", function () {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
delegateToCalls(spyApi, "yieldTo", false, "yieldTo", function (property) {
throw new Error(this.toString() + " cannot yield to '" + property +
"' since it was not yet invoked.");
});
delegateToCalls(spyApi, "yieldToOn", false, "yieldToOn", function (property) {
throw new Error(this.toString() + " cannot yield to '" + property +
"' since it was not yet invoked.");
});
return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1];
},
spyApi.formatters = {
"c": function (spy) {
return sinon.timesInWords(spy.callCount);
},
withArgs: function () {
var args = slice.call(arguments);
"n": function (spy) {
return spy.toString();
},
if (this.fakes) {
var match = matchingFake(this.fakes, args, true);
"C": function (spy) {
var calls = [];
for (var i = 0, l = spy.callCount; i < l; ++i) {
var stringifiedCall = " " + spy.getCall(i).toString();
if (/\n/.test(calls[i - 1])) {
stringifiedCall = "\n" + stringifiedCall;
}
push.call(calls, stringifiedCall);
if (match) {
return match;
}
} else {
this.fakes = [];
}
return calls.length > 0 ? "\n" + calls.join("\n") : "";
},
var original = this;
var fake = this._create();
fake.matchingAguments = args;
push.call(this.fakes, fake);
"t": function (spy) {
var objects = [];
fake.withArgs = function () {
return original.withArgs.apply(original, arguments);
};
for (var i = 0, l = spy.callCount; i < l; ++i) {
push.call(objects, sinon.format(spy.thisValues[i]));
for (var i = 0; i < this.args.length; i++) {
if (fake.matches(this.args[i])) {
incrementCallCount.call(fake);
push.call(fake.thisValues, this.thisValues[i]);
push.call(fake.args, this.args[i]);
push.call(fake.returnValues, this.returnValues[i]);
push.call(fake.exceptions, this.exceptions[i]);
push.call(fake.callIds, this.callIds[i]);
}
return objects.join(", ");
},
"*": function (spy, args) {
var formatted = [];
for (var i = 0, l = args.length; i < l; ++i) {
push.call(formatted, sinon.format(args[i]));
}
return formatted.join(", ");
}
};
createCallProperties.call(fake);
return spyApi;
}()));
return fake;
},
spyCall = (function () {
matches: function (args, strict) {
var margs = this.matchingAguments;
function throwYieldError(proxy, text, args) {
var msg = sinon.functionName(proxy) + text;
if (args.length) {
msg += " Received [" + slice.call(args).join(", ") + "]";
if (margs.length <= args.length &&
sinon.deepEqual(margs, args.slice(0, margs.length))) {
return !strict || margs.length == args.length;
}
throw new Error(msg);
}
},
var callApi = {
create: function create(spy, thisValue, args, returnValue, exception, id) {
var proxyCall = sinon.create(spyCall);
delete proxyCall.create;
proxyCall.proxy = spy;
proxyCall.thisValue = thisValue;
proxyCall.args = args;
proxyCall.returnValue = returnValue;
proxyCall.exception = exception;
proxyCall.callId = typeof id == "number" && id || callId++;
printf: function (format) {
var spy = this;
var args = slice.call(arguments, 1);
var formatter;
return proxyCall;
},
return (format || "").replace(/%(.)/g, function (match, specifyer) {
formatter = spyApi.formatters[specifyer];
calledOn: function calledOn(thisValue) {
if (sinon.match && sinon.match.isMatcher(thisValue)) {
return thisValue.test(this.thisValue);
if (typeof formatter == "function") {
return formatter.call(null, spy, args);
} else if (!isNaN(parseInt(specifyer), 10)) {
return sinon.format(args[specifyer - 1]);
}
return this.thisValue === thisValue;
},
calledWith: function calledWith() {
for (var i = 0, l = arguments.length; i < l; i += 1) {
if (!sinon.deepEqual(arguments[i], this.args[i])) {
return false;
}
}
return "%" + specifyer;
});
}
};
return true;
},
calledWithMatch: function calledWithMatch() {
for (var i = 0, l = arguments.length; i < l; i += 1) {
var actual = this.args[i];
var expectation = arguments[i];
if (!sinon.match || !sinon.match(expectation).test(actual)) {
return false;
}
function delegateToCalls(method, matchAny, actual, notCalled) {
spyApi[method] = function () {
if (!this.called) {
if (notCalled) {
return notCalled.apply(this, arguments);
}
return true;
},
return false;
}
calledWithExactly: function calledWithExactly() {
return arguments.length == this.args.length &&
this.calledWith.apply(this, arguments);
},
var currentCall;
var matches = 0;
notCalledWith: function notCalledWith() {
return !this.calledWith.apply(this, arguments);
},
for (var i = 0, l = this.callCount; i < l; i += 1) {
currentCall = this.getCall(i);
notCalledWithMatch: function notCalledWithMatch() {
return !this.calledWithMatch.apply(this, arguments);
},
if (currentCall[actual || method].apply(currentCall, arguments)) {
matches += 1;
returned: function returned(value) {
return sinon.deepEqual(value, this.returnValue);
},
threw: function threw(error) {
if (typeof error == "undefined" || !this.exception) {
return !!this.exception;
if (matchAny) {
return true;
}
}
}
if (typeof error == "string") {
return this.exception.name == error;
}
return matches === this.callCount;
};
}
return this.exception === error;
},
delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
delegateToCalls("calledWith", true);
delegateToCalls("calledWithMatch", true);
delegateToCalls("alwaysCalledWith", false, "calledWith");
delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch");
delegateToCalls("calledWithExactly", true);
delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly");
delegateToCalls("neverCalledWith", false, "notCalledWith",
function () { return true; });
delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch",
function () { return true; });
delegateToCalls("threw", true);
delegateToCalls("alwaysThrew", false, "threw");
delegateToCalls("returned", true);
delegateToCalls("alwaysReturned", false, "returned");
delegateToCalls("calledWithNew", true);
delegateToCalls("alwaysCalledWithNew", false, "calledWithNew");
delegateToCalls("callArg", false, "callArgWith", function () {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgWith = spyApi.callArg;
delegateToCalls("callArgOn", false, "callArgOnWith", function () {
throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
});
spyApi.callArgOnWith = spyApi.callArgOn;
delegateToCalls("yield", false, "yield", function () {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
// "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
spyApi.invokeCallback = spyApi.yield;
delegateToCalls("yieldOn", false, "yieldOn", function () {
throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
});
delegateToCalls("yieldTo", false, "yieldTo", function (property) {
throw new Error(this.toString() + " cannot yield to '" + property +
"' since it was not yet invoked.");
});
delegateToCalls("yieldToOn", false, "yieldToOn", function (property) {
throw new Error(this.toString() + " cannot yield to '" + property +
"' since it was not yet invoked.");
});
calledWithNew: function calledWithNew(thisValue) {
return this.thisValue instanceof this.proxy;
},
spyApi.formatters = {
"c": function (spy) {
return sinon.timesInWords(spy.callCount);
},
calledBefore: function (other) {
return this.callId < other.callId;
},
"n": function (spy) {
return spy.toString();
},
calledAfter: function (other) {
return this.callId > other.callId;
},
"C": function (spy) {
var calls = [];
callArg: function (pos) {
this.args[pos]();
},
callArgOn: function (pos, thisValue) {
this.args[pos].apply(thisValue);
},
callArgWith: function (pos) {
this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1)));
},
callArgOnWith: function (pos, thisValue) {
var args = slice.call(arguments, 2);
this.args[pos].apply(thisValue, args);
},
"yield": function () {
this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0)));
},
yieldOn: function (thisValue) {
var args = this.args;
for (var i = 0, l = args.length; i < l; ++i) {
if (typeof args[i] === "function") {
args[i].apply(thisValue, slice.call(arguments, 1));
return;
}
for (var i = 0, l = spy.callCount; i < l; ++i) {
var stringifiedCall = " " + spy.getCall(i).toString();
if (/\n/.test(calls[i - 1])) {
stringifiedCall = "\n" + stringifiedCall;
}
throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
},
push.call(calls, stringifiedCall);
}
yieldTo: function (prop) {
this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1)));
},
return calls.length > 0 ? "\n" + calls.join("\n") : "";
},
yieldToOn: function (prop, thisValue) {
var args = this.args;
for (var i = 0, l = args.length; i < l; ++i) {
if (args[i] && typeof args[i][prop] === "function") {
args[i][prop].apply(thisValue, slice.call(arguments, 2));
return;
}
}
throwYieldError(this.proxy, " cannot yield to '" + prop +
"' since no callback was passed.", args);
},
"t": function (spy) {
var objects = [];
toString: function () {
var callStr = this.proxy.toString() + "(";
var args = [];
for (var i = 0, l = spy.callCount; i < l; ++i) {
push.call(objects, sinon.format(spy.thisValues[i]));
}
for (var i = 0, l = this.args.length; i < l; ++i) {
push.call(args, sinon.format(this.args[i]));
}
return objects.join(", ");
},
callStr = callStr + args.join(", ") + ")";
"*": function (spy, args) {
var formatted = [];
if (typeof this.returnValue != "undefined") {
callStr += " => " + sinon.format(this.returnValue);
}
for (var i = 0, l = args.length; i < l; ++i) {
push.call(formatted, sinon.format(args[i]));
}
if (this.exception) {
callStr += " !" + this.exception.name;
return formatted.join(", ");
}
};
if (this.exception.message) {
callStr += "(" + this.exception.message + ")";
}
}
sinon.extend(spy, spyApi);
return callStr;
}
};
callApi.invokeCallback = callApi.yield;
return callApi;
}());
spy.spyCall = sinon.spyCall;
spy.spyCall = spyCall;
// This steps outside the module sandbox and will be removed
sinon.spyCall = spyCall;
if (commonJSModule) {

@@ -566,0 +389,0 @@ module.exports = spy;

@@ -24,11 +24,12 @@ /*jslint eqeqeq: false, onevar: false*/

sinon.Event = function Event(type, bubbles, cancelable) {
this.initEvent(type, bubbles, cancelable);
sinon.Event = function Event(type, bubbles, cancelable, target) {
this.initEvent(type, bubbles, cancelable, target);
};
sinon.Event.prototype = {
initEvent: function(type, bubbles, cancelable) {
initEvent: function(type, bubbles, cancelable, target) {
this.type = type;
this.bubbles = bubbles;
this.cancelable = cancelable;
this.target = target;
},

@@ -35,0 +36,0 @@

@@ -62,2 +62,14 @@ /**

var xhr = this;
["loadstart", "load", "abort", "loadend"].forEach(function (eventName) {
xhr.addEventListener(eventName, function (event) {
var listener = xhr["on" + eventName];
if (listener && typeof listener == "function") {
listener(event);
}
});
});
if (typeof FakeXMLHttpRequest.onCreate == "function") {

@@ -216,2 +228,9 @@ FakeXMLHttpRequest.onCreate(this);

this.dispatchEvent(new sinon.Event("readystatechange"));
switch (this.readyState) {
case FakeXMLHttpRequest.DONE:
this.dispatchEvent(new sinon.Event("load", false, false, this));
this.dispatchEvent(new sinon.Event("loadend", false, false, this));
break;
}
},

@@ -272,2 +291,4 @@

}
this.dispatchEvent(new sinon.Event("loadstart", false, false, this));
},

@@ -287,2 +308,4 @@

this.readyState = sinon.FakeXMLHttpRequest.UNSENT;
this.dispatchEvent(new sinon.Event("abort", false, false, this));
},

@@ -289,0 +312,0 @@

{
"name": "sinon",
"description": "JavaScript test spies, stubs and mocks.",
"version": "1.6.0",
"version": "1.7.0",
"homepage": "http://cjohansen.no/sinon/",

@@ -6,0 +6,0 @@ "author": "Christian Johansen",

/**
* Sinon.JS 1.6.0, 2013/02/18
* Sinon.JS 1.7.0, 2013/05/07
*

@@ -4,0 +4,0 @@ * @author Christian Johansen (christian@cjohansen.no)

require("../sinon_test.js");
require("../sinon/spy_test.js");
require("../sinon/call_test.js");
require("../sinon/stub_test.js");

@@ -4,0 +5,0 @@ require("../sinon/mock_test.js");

@@ -503,3 +503,38 @@ /*jslint onevar: false, eqeqeq: false*/

}
},
".restore": {
"restores all methods of supplied object": function () {
var methodA = function () {};
var methodB = function () {};
var obj = { methodA: methodA, methodB: methodB };
sinon.stub(obj);
sinon.restore(obj);
assert.same(obj.methodA, methodA);
assert.same(obj.methodB, methodB);
},
"only restores restorable methods": function () {
var stubbedMethod = function () {};
var vanillaMethod = function () {};
var obj = { stubbedMethod: stubbedMethod, vanillaMethod: vanillaMethod };
sinon.stub(obj, "stubbedMethod");
sinon.restore(obj);
assert.same(obj.stubbedMethod, stubbedMethod);
},
"restores a single stubbed method": function () {
var method = function () {};
var obj = { method: method };
sinon.stub(obj);
sinon.restore(obj.method);
assert.same(obj.method, method);
}
}
});

@@ -1050,2 +1050,30 @@ /*jslint onevar: false*/

"assert.callOrder with missing first call exception message": function () {
var obj = { doop: function () {}, foo: function () {} };
sinon.spy(obj, "doop");
sinon.spy(obj, "foo");
obj.foo();
var message = this.message("callOrder", obj.doop, obj.foo);
assert.equals(message,
"expected doop, foo to be called in " +
"order but were called as foo");
},
"assert.callOrder with missing last call exception message": function () {
var obj = { doop: function () {}, foo: function () {} };
sinon.spy(obj, "doop");
sinon.spy(obj, "foo");
obj.doop();
var message = this.message("callOrder", obj.doop, obj.foo);
assert.equals(message,
"expected doop, foo to be called in " +
"order but were called as doop");
},
"assert.callCount exception message": function () {

@@ -1052,0 +1080,0 @@ this.obj.doSomething();

@@ -994,3 +994,3 @@ /*jslint onevar: false, eqeqeq: false, browser: true*/

},
"filtering": {

@@ -1236,4 +1236,160 @@ setUp: function () {

}
},
"progress events": {
setUp: function () {
this.xhr = new sinon.FakeXMLHttpRequest();
this.xhr.open("GET", "/some/url")
},
"triggers 'loadstart' event on #send": function (done) {
this.xhr.addEventListener("loadstart", function () {
assert(true);
done();
});
this.xhr.send();
},
"triggers 'loadstart' with event target set to the XHR object": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("loadstart", function (event) {
assert.same(xhr, event.target);
done();
});
this.xhr.send();
},
"calls #onloadstart on #send": function (done) {
this.xhr.onloadstart = function () {
assert(true);
done();
};
this.xhr.send();
},
"triggers 'load' event on success": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("load", function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.DONE);
refute.equals(xhr.status, 0);
done();
});
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"triggers 'load' with event target set to the XHR object": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("load", function (event) {
assert.same(xhr, event.target);
done();
});
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"calls #onload on success": function (done) {
var xhr = this.xhr;
this.xhr.onload = function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.DONE);
refute.equals(xhr.status, 0);
done();
};
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"triggers 'abort' event on cancel": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("abort", function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.UNSENT);
assert.equals(xhr.status, 0);
done();
});
this.xhr.send();
this.xhr.abort();
},
"triggers 'abort' with event target set to the XHR object": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("abort", function (event) {
assert.same(xhr, event.target);
done();
});
this.xhr.send();
this.xhr.abort();
},
"calls #onabort on cancel": function (done) {
var xhr = this.xhr;
this.xhr.onabort = function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.UNSENT);
assert.equals(xhr.status, 0);
done();
};
this.xhr.send();
this.xhr.abort();
},
"triggers 'loadend' event at the end": function (done) {
this.xhr.addEventListener("loadend", function () {
assert(true);
done();
});
this.xhr.send();
this.xhr.respond(403, {}, "");
},
"triggers 'loadend' with event target set to the XHR object": function (done) {
var xhr = this.xhr;
this.xhr.addEventListener("loadend", function (event) {
assert.same(xhr, event.target);
done();
});
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"calls #onloadend at the end": function (done) {
this.xhr.onloadend = function () {
assert(true);
done();
};
this.xhr.send();
this.xhr.respond(403, {}, "");
}
}
});
}(this));

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc