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.7.3 to 1.8.1

lib/sinon/behavior.js

66

lib/sinon.js

@@ -13,3 +13,3 @@ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/

var sinon = (function (buster) {
var sinon = (function (formatio) {
var div = typeof document != "undefined" && document.createElement("div");

@@ -67,6 +67,7 @@ var hasOwn = Object.prototype.hasOwnProperty;

var wrappedMethod = object[property];
var wrappedMethod = object[property],
error;
if (!isFunction(wrappedMethod)) {
throw new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
property + " as function");

@@ -76,3 +77,3 @@ }

if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
throw new TypeError("Attempted to wrap " + property + " which is already wrapped");
error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
}

@@ -82,9 +83,20 @@

var verb = !!wrappedMethod.returns ? "stubbed" : "spied on";
throw new TypeError("Attempted to wrap " + property + " which is already " + verb);
error = new TypeError("Attempted to wrap " + property + " which is already " + verb);
}
// IE 8 does not support hasOwnProperty on the window object.
var owned = hasOwn.call(object, property);
if (error) {
if (wrappedMethod._stack) {
error.stack += '\n--------------\n' + wrappedMethod._stack;
}
throw error;
}
// IE 8 does not support hasOwnProperty on the window object and Firefox has a problem
// when using hasOwn.call on objects from other frames.
var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property);
object[property] = method;
method.displayName = property;
// Set up a stack trace which can be used later to find what line of
// code the original method was created on.
method._stack = (new Error('Stack Trace for original')).stack;

@@ -158,16 +170,2 @@ method.restore = function () {

if (aString == "[object Array]") {
if (a.length !== b.length) {
return false;
}
for (var i = 0, l = a.length; i < l; i += 1) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
if (aString == "[object Date]") {

@@ -179,2 +177,6 @@ return a.valueOf() === b.valueOf();

if (aString == "[object Array]" && a.length !== b.length) {
return false;
}
for (prop in a) {

@@ -286,3 +288,3 @@ aLength += 1;

logError: function (label, err) {
var msg = label + " threw exception: "
var msg = label + " threw exception: ";
sinon.log(msg + "[" + err.name + "] " + err.message);

@@ -329,10 +331,17 @@ if (err.stack) { sinon.log(err.stack); }

var isNode = typeof module == "object" && typeof require == "function";
var isNode = typeof module !== "undefined" && module.exports;
var isAMD = typeof define === 'function' && typeof define.amd === 'object' && define.amd;
if (isNode) {
if (isAMD) {
define(function(){
return sinon;
});
} else if (isNode) {
try {
buster = { format: require("buster-format") };
formatio = require("formatio");
} catch (e) {}
module.exports = sinon;
module.exports.spy = require("./sinon/spy");
module.exports.spyCall = require("./sinon/call");
module.exports.behavior = require("./sinon/behavior");
module.exports.stub = require("./sinon/stub");

@@ -349,5 +358,4 @@ module.exports.mock = require("./sinon/mock");

if (buster) {
var formatter = sinon.create(buster.format);
formatter.quoteStrings = false;
if (formatio) {
var formatter = formatio.configure({ quoteStrings: false });
sinon.format = function () {

@@ -369,2 +377,2 @@ return formatter.ascii.apply(formatter, arguments);

return sinon;
}(typeof buster == "object" && buster));
}(typeof formatio == "object" && formatio));

@@ -18,3 +18,3 @@ /**

(function (sinon, global) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== "undefined" && module.exports;
var slice = Array.prototype.slice;

@@ -87,3 +87,3 @@ var assert;

prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1);
};
}

@@ -90,0 +90,0 @@ assert = {

@@ -20,3 +20,3 @@ /**

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;
if (!sinon && commonJSModule) {

@@ -94,3 +94,3 @@ sinon = require("../sinon");

calledWithNew: function calledWithNew(thisValue) {
calledWithNew: function calledWithNew() {
return this.thisValue instanceof this.proxy;

@@ -196,3 +196,3 @@ },

return proxyCall;
};
}
createSpyCall.toString = callProto.toString; // used by mocks

@@ -199,0 +199,0 @@

@@ -19,3 +19,3 @@ /**

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;
var push = [].push;

@@ -22,0 +22,0 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -15,3 +15,3 @@ /* @depend ../sinon.js */

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;

@@ -18,0 +18,0 @@ if (!sinon && commonJSModule) {

@@ -18,4 +18,5 @@ /**

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;
var push = [].push;
var match;

@@ -30,2 +31,8 @@ if (!sinon && commonJSModule) {

match = sinon.match;
if (!match && commonJSModule) {
match = require("./match");
}
function mock(object) {

@@ -211,2 +218,10 @@ if (!object) {

function verifyMatcher(possibleMatcher, arg){
if (match && match.isMatcher(possibleMatcher)) {
return possibleMatcher.test(arg);
} else {
return true;
}
}
return {

@@ -321,2 +336,8 @@ minCalls: 1,

for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
if (!verifyMatcher(this.expectedArguments[i],args[i])) {
sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +
", didn't match " + this.expectedArguments.toString());
}
if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {

@@ -354,2 +375,6 @@ sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) +

for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
if (!verifyMatcher(this.expectedArguments[i],args[i])) {
return false;
}
if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {

@@ -356,0 +381,0 @@ return false;

@@ -20,3 +20,3 @@ /**

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
var sinon = require("../sinon");

@@ -34,3 +34,3 @@ sinon.extend(sinon, require("./util/fake_timers"));

if (config.injectInto) {
if (config.injectInto && !(key in config.injectInto) ) {
config.injectInto[key] = value;

@@ -124,5 +124,5 @@ } else {

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon.sandbox;
}
}());
/**
* @depend ../sinon.js
* @depend match.js
* @depend call.js
*/

@@ -8,197 +8,2 @@ /*jslint eqeqeq: false, onevar: false, plusplus: false*/

/**
* Spy calls
*
* @author Christian Johansen (christian@cjohansen.no)
* @author Maximilian Antoni (mail@maxantoni.de)
* @license BSD
*
* Copyright (c) 2010-2013 Christian Johansen
* Copyright (c) 2013 Maximilian Antoni
*/
"use strict";
var commonJSModule = typeof module == "object" && typeof require == "function";
if (!this.sinon && commonJSModule) {
var sinon = require("../sinon");
}
(function (sinon) {
function throwYieldError(proxy, text, args) {
var msg = sinon.functionName(proxy) + text;
if (args.length) {
msg += " Received [" + slice.call(args).join(", ") + "]";
}
throw new Error(msg);
}
var slice = Array.prototype.slice;
var callProto = {
calledOn: function calledOn(thisValue) {
if (sinon.match && sinon.match.isMatcher(thisValue)) {
return thisValue.test(this.thisValue);
}
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 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;
}
}
return true;
},
calledWithExactly: function calledWithExactly() {
return arguments.length == this.args.length &&
this.calledWith.apply(this, arguments);
},
notCalledWith: function notCalledWith() {
return !this.calledWith.apply(this, arguments);
},
notCalledWithMatch: function notCalledWithMatch() {
return !this.calledWithMatch.apply(this, arguments);
},
returned: function returned(value) {
return sinon.deepEqual(value, this.returnValue);
},
threw: function threw(error) {
if (typeof error === "undefined" || !this.exception) {
return !!this.exception;
}
return this.exception === error || this.exception.name === error;
},
calledWithNew: function calledWithNew(thisValue) {
return this.thisValue instanceof this.proxy;
},
calledBefore: function (other) {
return this.callId < other.callId;
},
calledAfter: function (other) {
return this.callId > other.callId;
},
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;
}
}
throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
},
yieldTo: function (prop) {
this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1)));
},
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);
},
toString: function () {
var callStr = this.proxy.toString() + "(";
var args = [];
for (var i = 0, l = this.args.length; i < l; ++i) {
args.push(sinon.format(this.args[i]));
}
callStr = callStr + args.join(", ") + ")";
if (typeof this.returnValue != "undefined") {
callStr += " => " + sinon.format(this.returnValue);
}
if (this.exception) {
callStr += " !" + this.exception.name;
if (this.exception.message) {
callStr += "(" + this.exception.message + ")";
}
}
return callStr;
}
};
callProto.invokeCallback = callProto.yield;
function createSpyCall(spy, thisValue, args, returnValue, exception, id) {
if (typeof id !== "number") {
throw new TypeError("Call id is not a number");
}
var proxyCall = sinon.create(callProto);
proxyCall.proxy = spy;
proxyCall.thisValue = thisValue;
proxyCall.args = args;
proxyCall.returnValue = returnValue;
proxyCall.exception = exception;
proxyCall.callId = id;
return proxyCall;
};
createSpyCall.toString = callProto.toString; // used by mocks
sinon.spyCall = createSpyCall;
}(typeof sinon == "object" && sinon || null));
/**
* @depend ../sinon.js
*/
/*jslint eqeqeq: false, onevar: false, plusplus: false*/
/*global module, require, sinon*/
/**
* Spy functions

@@ -214,3 +19,3 @@ *

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;
var push = Array.prototype.push;

@@ -220,2 +25,10 @@ var slice = Array.prototype.slice;

if (!sinon && commonJSModule) {
sinon = require("../sinon");
}
if (!sinon) {
return;
}
function spy(object, property) {

@@ -239,4 +52,2 @@ if (!property && typeof object == "function") {

var alen = args.length;
for (var i = 0, l = fakes.length; i < l; i++) {

@@ -348,10 +159,12 @@ if (fakes[i].matches(args, strict)) {

}
var thisCall = this.getCall(this.callCount - 1);
if (thisCall.calledWithNew() && typeof returnValue !== 'object') {
returnValue = thisValue;
}
} catch (e) {
push.call(this.returnValues, undefined);
exception = e;
throw e;
} finally {
push.call(this.exceptions, exception);
}
push.call(this.exceptions, exception);
push.call(this.returnValues, returnValue);

@@ -361,2 +174,6 @@

if (exception !== undefined) {
throw exception;
}
return returnValue;

@@ -375,2 +192,13 @@ },

getCalls: function () {
var calls = [];
var i;
for (i = 0; i < this.callCount; i++) {
calls.push(this.getCall(i));
}
return calls;
},
calledBefore: function calledBefore(spyFn) {

@@ -412,2 +240,3 @@ if (!this.called) {

fake.matchingAguments = args;
fake.parent = this;
push.call(this.fakes, fake);

@@ -453,3 +282,3 @@

return formatter.call(null, spy, args);
} else if (!isNaN(parseInt(specifyer), 10)) {
} else if (!isNaN(parseInt(specifyer, 10))) {
return sinon.format(args[specifyer - 1]);

@@ -456,0 +285,0 @@ }

/**
* @depend ../sinon.js
* @depend spy.js
* @depend behavior.js
*/

@@ -18,3 +19,3 @@ /*jslint eqeqeq: false, onevar: false*/

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;

@@ -42,7 +43,7 @@ if (!sinon && commonJSModule) {

if (!object && !property) {
if (!object && typeof property === "undefined") {
return sinon.stub.create();
}
if (!property && !!object && typeof object == "object") {
if (typeof property === "undefined" && typeof object == "object") {
for (var prop in object) {

@@ -60,124 +61,22 @@ if (typeof object[prop] === "function") {

function getChangingValue(stub, property) {
var index = stub.callCount - 1;
var values = stub[property];
var prop = index in values ? values[index] : values[values.length - 1];
stub[property + "Last"] = prop;
return prop;
function getDefaultBehavior(stub) {
return stub.defaultBehavior || getParentBehaviour(stub) || sinon.behavior.create(stub);
}
function getCallback(stub, args) {
var callArgAt = getChangingValue(stub, "callArgAts");
if (callArgAt < 0) {
var callArgProp = getChangingValue(stub, "callArgProps");
for (var i = 0, l = args.length; i < l; ++i) {
if (!callArgProp && typeof args[i] == "function") {
return args[i];
}
if (callArgProp && args[i] &&
typeof args[i][callArgProp] == "function") {
return args[i][callArgProp];
}
}
return null;
}
return args[callArgAt];
function getParentBehaviour(stub) {
return (stub.parent && getCurrentBehavior(stub.parent));
}
var join = Array.prototype.join;
function getCallbackError(stub, func, args) {
if (stub.callArgAtsLast < 0) {
var msg;
if (stub.callArgPropsLast) {
msg = sinon.functionName(stub) +
" expected to yield to '" + stub.callArgPropsLast +
"', but no object with such a property was passed."
} else {
msg = sinon.functionName(stub) +
" expected to yield, but no callback was passed."
}
if (args.length > 0) {
msg += " Received [" + join.call(args, ", ") + "]";
}
return msg;
}
return "argument at index " + stub.callArgAtsLast + " is not a function: " + func;
function getCurrentBehavior(stub) {
var behavior = stub.behaviors[stub.callCount - 1];
return behavior && behavior.isPresent() ? behavior : getDefaultBehavior(stub);
}
var nextTick = (function () {
if (typeof process === "object" && typeof process.nextTick === "function") {
return process.nextTick;
} else if (typeof setImmediate === "function") {
return setImmediate;
} else {
return function (callback) {
setTimeout(callback, 0);
};
}
})();
function callCallback(stub, args) {
if (stub.callArgAts.length > 0) {
var func = getCallback(stub, args);
if (typeof func != "function") {
throw new TypeError(getCallbackError(stub, func, args));
}
var callbackArguments = getChangingValue(stub, "callbackArguments");
var callbackContext = getChangingValue(stub, "callbackContexts");
if (stub.callbackAsync) {
nextTick(function() {
func.apply(callbackContext, callbackArguments);
});
} else {
func.apply(callbackContext, callbackArguments);
}
}
}
var uuid = 0;
sinon.extend(stub, (function () {
var slice = Array.prototype.slice, proto;
function throwsException(error, message) {
if (typeof error == "string") {
this.exception = new Error(message || "");
this.exception.name = error;
} else if (!error) {
this.exception = new Error("Error");
} else {
this.exception = error;
}
return this;
}
proto = {
var proto = {
create: function create() {
var functionStub = function () {
callCallback(functionStub, arguments);
if (functionStub.exception) {
throw functionStub.exception;
} else if (typeof functionStub.returnArgAt == 'number') {
return arguments[functionStub.returnArgAt];
} else if (functionStub.returnThis) {
return this;
}
return functionStub.returnValue;
return getCurrentBehavior(functionStub).invoke(this, arguments);
};

@@ -190,7 +89,2 @@

functionStub.callArgAts = [];
functionStub.callbackArguments = [];
functionStub.callbackContexts = [];
functionStub.callArgProps = [];
sinon.extend(functionStub, stub);

@@ -201,2 +95,5 @@ functionStub._create = sinon.stub.create;

functionStub.defaultBehavior = null;
functionStub.behaviors = [];
return functionStub;

@@ -208,6 +105,4 @@ },

this.callArgAts = [];
this.callbackArguments = [];
this.callbackContexts = [];
this.callArgProps = [];
this.defaultBehavior = null;
this.behaviors = [];

@@ -225,142 +120,36 @@ delete this.returnValue;

returns: function returns(value) {
this.returnValue = value;
return this;
},
returnsArg: function returnsArg(pos) {
if (typeof pos != "number") {
throw new TypeError("argument index is not number");
onCall: function(index) {
if (!this.behaviors[index]) {
this.behaviors[index] = sinon.behavior.create(this);
}
this.returnArgAt = pos;
return this;
return this.behaviors[index];
},
returnsThis: function returnsThis() {
this.returnThis = true;
return this;
onFirstCall: function() {
return this.onCall(0);
},
"throws": throwsException,
throwsException: throwsException,
callsArg: function callsArg(pos) {
if (typeof pos != "number") {
throw new TypeError("argument index is not number");
}
this.callArgAts.push(pos);
this.callbackArguments.push([]);
this.callbackContexts.push(undefined);
this.callArgProps.push(undefined);
return this;
onSecondCall: function() {
return this.onCall(1);
},
callsArgOn: function callsArgOn(pos, context) {
if (typeof pos != "number") {
throw new TypeError("argument index is not number");
}
if (typeof context != "object") {
throw new TypeError("argument context is not an object");
}
this.callArgAts.push(pos);
this.callbackArguments.push([]);
this.callbackContexts.push(context);
this.callArgProps.push(undefined);
return this;
},
callsArgWith: function callsArgWith(pos) {
if (typeof pos != "number") {
throw new TypeError("argument index is not number");
}
this.callArgAts.push(pos);
this.callbackArguments.push(slice.call(arguments, 1));
this.callbackContexts.push(undefined);
this.callArgProps.push(undefined);
return this;
},
callsArgOnWith: function callsArgWith(pos, context) {
if (typeof pos != "number") {
throw new TypeError("argument index is not number");
}
if (typeof context != "object") {
throw new TypeError("argument context is not an object");
}
this.callArgAts.push(pos);
this.callbackArguments.push(slice.call(arguments, 2));
this.callbackContexts.push(context);
this.callArgProps.push(undefined);
return this;
},
yields: function () {
this.callArgAts.push(-1);
this.callbackArguments.push(slice.call(arguments, 0));
this.callbackContexts.push(undefined);
this.callArgProps.push(undefined);
return this;
},
yieldsOn: function (context) {
if (typeof context != "object") {
throw new TypeError("argument context is not an object");
}
this.callArgAts.push(-1);
this.callbackArguments.push(slice.call(arguments, 1));
this.callbackContexts.push(context);
this.callArgProps.push(undefined);
return this;
},
yieldsTo: function (prop) {
this.callArgAts.push(-1);
this.callbackArguments.push(slice.call(arguments, 1));
this.callbackContexts.push(undefined);
this.callArgProps.push(prop);
return this;
},
yieldsToOn: function (prop, context) {
if (typeof context != "object") {
throw new TypeError("argument context is not an object");
}
this.callArgAts.push(-1);
this.callbackArguments.push(slice.call(arguments, 2));
this.callbackContexts.push(context);
this.callArgProps.push(prop);
return this;
onThirdCall: function() {
return this.onCall(2);
}
};
// create asynchronous versions of callsArg* and yields* methods
for (var method in proto) {
// need to avoid creating anotherasync versions of the newly added async methods
if (proto.hasOwnProperty(method) &&
method.match(/^(callsArg|yields|thenYields$)/) &&
!method.match(/Async/)) {
proto[method + 'Async'] = (function (syncFnName) {
return function () {
this.callbackAsync = true;
return this[syncFnName].apply(this, arguments);
for (var method in sinon.behavior) {
if (sinon.behavior.hasOwnProperty(method) &&
!proto.hasOwnProperty(method) &&
method != 'create' &&
method != 'withArgs' &&
method != 'invoke') {
proto[method] = (function(behaviorMethod) {
return function() {
this.defaultBehavior = this.defaultBehavior || sinon.behavior.create(this);
this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
return this;
};
})(method);
}(method));
}

@@ -370,3 +159,2 @@ }

return proto;
}()));

@@ -373,0 +161,0 @@

@@ -18,3 +18,3 @@ /**

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;

@@ -21,0 +21,0 @@ if (!sinon && commonJSModule) {

@@ -20,3 +20,3 @@ /**

(function (sinon) {
var commonJSModule = typeof module == "object" && typeof require == "function";
var commonJSModule = typeof module !== 'undefined' && module.exports;

@@ -23,0 +23,0 @@ if (!sinon && commonJSModule) {

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

sinon.EventTarget = {
addEventListener: function addEventListener(event, listener, useCapture) {
addEventListener: function addEventListener(event, listener) {
this.eventListeners = this.eventListeners || {};

@@ -51,3 +51,3 @@ this.eventListeners[event] = this.eventListeners[event] || [];

removeEventListener: function removeEventListener(event, listener, useCapture) {
removeEventListener: function removeEventListener(event, listener) {
var listeners = this.eventListeners && this.eventListeners[event] || [];

@@ -54,0 +54,0 @@

@@ -60,3 +60,2 @@ /**

function match(response, request) {
var requestMethod = this.getHTTPMethod(request);
var requestUrl = request.url;

@@ -71,3 +70,3 @@

var ru = response.url;
var args = [request].concat(!ru ? [] : requestUrl.match(ru).slice(1));
var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []);
return response.response.apply(response, args);

@@ -110,12 +109,12 @@ }

server.handleRequest(this);
};
if (this.autoRespond && !this.responding) {
setTimeout(function () {
server.responding = false;
server.respond();
}, this.autoRespondAfter || 10);
if (server.autoRespond && !server.responding) {
setTimeout(function () {
server.responding = false;
server.respond();
}, server.autoRespondAfter || 10);
this.responding = true;
}
server.responding = true;
}
};
},

@@ -173,5 +172,6 @@

var queue = this.queue || [];
var requests = queue.splice(0);
var request;
while(request = queue.shift()) {
while(request = requests.shift()) {
this.processRequest(request);

@@ -190,3 +190,3 @@ }

if (this.responses) {
for (var i = 0, l = this.responses.length; i < l; i++) {
for (var l = this.responses.length, i = l - 1; i >= 0; i--) {
if (match.call(this, this.responses[i], request)) {

@@ -215,4 +215,4 @@ response = this.responses[i].response;

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;
}

@@ -34,2 +34,6 @@ /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/

if (typeof args[0] === "undefined") {
throw new Error("Callback must be provided to timer calls");
}
var toId = id++;

@@ -136,2 +140,12 @@ var delay = args[1] || 0;

setImmediate: function setImmediate(callback) {
var passThruArgs = Array.prototype.slice.call(arguments, 1);
return addTimer.call(this, [callback, 0].concat(passThruArgs), false);
},
clearImmediate: function clearImmediate(timerId) {
this.clearTimeout(timerId);
},
tick: function tick(ms) {

@@ -167,3 +181,3 @@ ms = typeof ms == "number" ? ms : parseTime(ms);

firstTimerInRange: function (from, to) {
var timer, smallest, originalTimer;
var timer, smallest = null, originalTimer;

@@ -176,3 +190,3 @@ for (var id in this.timeouts) {

if (!smallest || this.timeouts[id].callAt < smallest) {
if (smallest === null || this.timeouts[id].callAt < smallest) {
originalTimer = this.timeouts[id];

@@ -283,2 +297,9 @@ smallest = this.timeouts[id].callAt;

target.prototype.toUTCString = source.prototype.toUTCString;
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
target[prop] = source[prop];
}
}
return target;

@@ -290,2 +311,10 @@ }

if (typeof global.setImmediate !== "undefined") {
methods.push("setImmediate");
}
if (typeof global.clearImmediate !== "undefined") {
methods.push("clearImmediate");
}
function restore() {

@@ -296,6 +325,9 @@ var method;

method = this.methods[i];
if (global[method].hadOwnProperty) {
global[method] = this["_" + method];
} else {
delete global[method];
try {
delete global[method];
} catch (e) {}
}

@@ -351,2 +383,4 @@ }

clearTimeout: clearTimeout,
setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined),
clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate: undefined),
setInterval: setInterval,

@@ -357,4 +391,4 @@ clearInterval: clearInterval,

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;
}

@@ -17,9 +17,10 @@ /**

if (typeof sinon == "undefined") {
this.sinon = {};
}
sinon.xhr = { XMLHttpRequest: this.XMLHttpRequest };
// wrapper for global
(function(global) {
if (typeof sinon === "undefined") {
global.sinon = {};
}
sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest };
var xhr = sinon.xhr;

@@ -32,2 +33,3 @@ xhr.GlobalXMLHttpRequest = global.XMLHttpRequest;

? function() { return new xhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0") } : false;
xhr.supportsCORS = 'withCredentials' in (new sinon.xhr.GlobalXMLHttpRequest());

@@ -63,3 +65,8 @@ /*jsl:ignore*/

this.statusText = "";
this.upload = new UploadProgress();
if (sinon.xhr.supportsCORS) {
this.withCredentials = false;
}
var xhr = this;

@@ -87,2 +94,37 @@ var events = ["loadstart", "load", "abort", "loadend"];

// An upload object is created for each
// FakeXMLHttpRequest and allows upload
// events to be simulated using uploadProgress
// and uploadError.
function UploadProgress() {
this.eventListeners = {
"progress": [],
"load": [],
"abort": [],
"error": []
}
}
UploadProgress.prototype.addEventListener = function(event, listener) {
this.eventListeners[event].push(listener);
};
UploadProgress.prototype.removeEventListener = function(event, listener) {
var listeners = this.eventListeners[event] || [];
for (var i = 0, l = listeners.length; i < l; ++i) {
if (listeners[i] == listener) {
return listeners.splice(i, 1);
}
}
};
UploadProgress.prototype.dispatchEvent = function(event) {
var listeners = this.eventListeners[event.type] || [];
for (var i = 0, listener; (listener = listeners[i]) != null; i++) {
listener(event);
}
};
function verifyState(xhr) {

@@ -109,3 +151,3 @@ if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {

if(callback(collection[index]) === true) return true;
};
}
return false;

@@ -122,3 +164,3 @@ }

case 5: return obj[method](args[0],args[1],args[2],args[3],args[4]);
};
}
};

@@ -162,3 +204,3 @@

}
if(fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr);
if(fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr, { target: fakeXhr });
};

@@ -244,2 +286,4 @@ if(xhr.addEventListener) {

this.dispatchEvent(new sinon.Event("loadend", false, false, this));
this.upload.dispatchEvent(new sinon.Event("load", false, false, this));
this.upload.dispatchEvent(new ProgressEvent("progress", {loaded: 100, total: 100}));
break;

@@ -320,2 +364,5 @@ }

this.dispatchEvent(new sinon.Event("abort", false, false, this));
this.upload.dispatchEvent(new sinon.Event("abort", false, false, this));
if (typeof this.onerror === "function") {

@@ -404,6 +451,10 @@ this.onerror();

this.setResponseBody(body || "");
if (typeof this.onload === "function"){
this.onload();
}
},
uploadProgress: function uploadProgress(progressEventRaw) {
this.upload.dispatchEvent(new ProgressEvent("progress", progressEventRaw));
},
uploadError: function uploadError(error) {
this.upload.dispatchEvent(new CustomEvent("error", {"detail": error}));
}

@@ -515,6 +566,7 @@ });

sinon.FakeXMLHttpRequest = FakeXMLHttpRequest;
})(this);
if (typeof module == "object" && typeof require == "function") {
})(typeof global === "object" ? global : this);
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;
}

@@ -17,2 +17,4 @@ /*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/

function clearTimeout() {}
function setImmediate() {}
function clearImmediate() {}
function setInterval() {}

@@ -26,4 +28,6 @@ function clearInterval() {}

clearTimeout = sinon.timers.clearTimeout;
setImmediate = sinon.timers.setImmediate;
clearImmediate = sinon.timers.clearImmediate;
setInterval = sinon.timers.setInterval;
clearInterval = sinon.timers.clearInterval;
Date = sinon.timers.Date;
{
"name": "sinon",
"description": "JavaScript test spies, stubs and mocks.",
"version": "1.7.3",
"version": "1.8.1",
"homepage": "http://cjohansen.no/sinon/",

@@ -25,3 +25,3 @@ "author": "Christian Johansen",

"dependencies": {
"buster-format": "~0.5"
"formatio": "~1.0"
},

@@ -28,0 +28,0 @@ "devDependencies": {

/**
* Sinon.JS 1.7.3, 2013/06/20
* Sinon.JS 1.7.3, 2013/10/18
*

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

/**
* Sinon.JS 1.7.3, 2013/06/20
* Sinon.JS 1.8.1, 2014/02/02
*

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

function clearTimeout() {}
function setImmediate() {}
function clearImmediate() {}
function setInterval() {}

@@ -61,2 +63,4 @@ function clearInterval() {}

clearTimeout = sinon.timers.clearTimeout;
setImmediate = sinon.timers.setImmediate;
clearImmediate = sinon.timers.clearImmediate;
setInterval = sinon.timers.setInterval;

@@ -63,0 +67,0 @@ clearInterval = sinon.timers.clearInterval;

/**
* Sinon.JS 1.7.3, 2013/06/20
* Sinon.JS 1.7.3, 2013/10/18
*

@@ -47,3 +47,3 @@ * @author Christian Johansen (christian@cjohansen.no)

var sinon = (function (buster) {
var sinon = (function (formatio) {
var div = typeof document != "undefined" && document.createElement("div");

@@ -101,6 +101,7 @@ var hasOwn = Object.prototype.hasOwnProperty;

var wrappedMethod = object[property];
var wrappedMethod = object[property],
error;
if (!isFunction(wrappedMethod)) {
throw new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +
property + " as function");

@@ -110,3 +111,3 @@ }

if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
throw new TypeError("Attempted to wrap " + property + " which is already wrapped");
error = new TypeError("Attempted to wrap " + property + " which is already wrapped");
}

@@ -116,5 +117,12 @@

var verb = !!wrappedMethod.returns ? "stubbed" : "spied on";
throw new TypeError("Attempted to wrap " + property + " which is already " + verb);
error = new TypeError("Attempted to wrap " + property + " which is already " + verb);
}
if (error) {
if (wrappedMethod._stack) {
error.stack += '\n--------------\n' + wrappedMethod._stack;
}
throw error;
}
// IE 8 does not support hasOwnProperty on the window object.

@@ -124,2 +132,3 @@ var owned = hasOwn.call(object, property);

method.displayName = property;
method._stack = (new Error('Stack Trace for original')).stack;

@@ -193,16 +202,2 @@ method.restore = function () {

if (aString == "[object Array]") {
if (a.length !== b.length) {
return false;
}
for (var i = 0, l = a.length; i < l; i += 1) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
if (aString == "[object Date]") {

@@ -214,2 +209,6 @@ return a.valueOf() === b.valueOf();

if (aString == "[object Array]" && a.length !== b.length) {
return false;
}
for (prop in a) {

@@ -363,10 +362,11 @@ aLength += 1;

var isNode = typeof module == "object" && typeof require == "function";
var isNode = typeof module !== "undefined" && module.exports;
if (isNode) {
try {
buster = { format: require("buster-format") };
formatio = require("formatio");
} catch (e) {}
module.exports = sinon;
module.exports.spy = require("./sinon/spy");
module.exports.spyCall = require("./sinon/call");
module.exports.stub = require("./sinon/stub");

@@ -383,5 +383,4 @@ module.exports.mock = require("./sinon/mock");

if (buster) {
var formatter = sinon.create(buster.format);
formatter.quoteStrings = false;
if (formatio) {
var formatter = formatio.configure({ quoteStrings: false });
sinon.format = function () {

@@ -403,3 +402,3 @@ return formatter.ascii.apply(formatter, arguments);

return sinon;
}(typeof buster == "object" && buster));
}(typeof formatio == "object" && formatio));

@@ -496,9 +495,10 @@ /*jslint eqeqeq: false, onevar: false*/

if (typeof sinon == "undefined") {
this.sinon = {};
}
sinon.xhr = { XMLHttpRequest: this.XMLHttpRequest };
// wrapper for global
(function(global) {
if (typeof sinon === "undefined") {
global.sinon = {};
}
sinon.xhr = { XMLHttpRequest: global.XMLHttpRequest };
var xhr = sinon.xhr;

@@ -875,6 +875,2 @@ xhr.GlobalXMLHttpRequest = global.XMLHttpRequest;

this.setResponseBody(body || "");
if (typeof this.onload === "function"){
this.onload();
}
}

@@ -986,5 +982,6 @@ });

sinon.FakeXMLHttpRequest = FakeXMLHttpRequest;
})(this);
if (typeof module == "object" && typeof require == "function") {
})(typeof global === "object" ? global : this);
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;

@@ -1061,3 +1058,3 @@ }

var ru = response.url;
var args = [request].concat(!ru ? [] : requestUrl.match(ru).slice(1));
var args = [request].concat(ru && typeof ru.exec == "function" ? ru.exec(requestUrl).slice(1) : []);
return response.response.apply(response, args);

@@ -1202,3 +1199,3 @@ }

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;

@@ -1370,3 +1367,3 @@ }

firstTimerInRange: function (from, to) {
var timer, smallest, originalTimer;
var timer, smallest = null, originalTimer;

@@ -1379,3 +1376,3 @@ for (var id in this.timeouts) {

if (!smallest || this.timeouts[id].callAt < smallest) {
if (smallest === null || this.timeouts[id].callAt < smallest) {
originalTimer = this.timeouts[id];

@@ -1556,3 +1553,3 @@ smallest = this.timeouts[id].callAt;

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;

@@ -1559,0 +1556,0 @@ }

/**
* Sinon.JS 1.7.3, 2013/06/20
* Sinon.JS 1.7.3, 2013/10/18
*

@@ -199,3 +199,3 @@ * @author Christian Johansen (christian@cjohansen.no)

firstTimerInRange: function (from, to) {
var timer, smallest, originalTimer;
var timer, smallest = null, originalTimer;

@@ -208,3 +208,3 @@ for (var id in this.timeouts) {

if (!smallest || this.timeouts[id].callAt < smallest) {
if (smallest === null || this.timeouts[id].callAt < smallest) {
originalTimer = this.timeouts[id];

@@ -385,4 +385,4 @@ smallest = this.timeouts[id].callAt;

if (typeof module == "object" && typeof require == "function") {
if (typeof module !== 'undefined' && module.exports) {
module.exports = sinon;
}
/**
* Sinon.JS 1.7.3, 2013/06/20
* Sinon.JS 1.7.3, 2013/10/18
*

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

@@ -13,2 +13,6 @@ # Sinon.JS

via [NuGet (package manager for Microsoft development platform)](https://www.nuget.org/packages/SinonJS)
Install-Package SinonJS
or install via git by cloning the repository and including sinon.js

@@ -54,6 +58,9 @@ in your project, as you would any other third party library.

Open `test/sinon.html` in a browser. To test against a built distribution, first
make sure you have a build (requires Ruby and Juicer):
make sure you have a build (requires [Ruby][ruby] and [Juicer][juicer]):
$ ./build
[ruby]: https://www.ruby-lang.org/en/
[juicer]: http://rubygems.org/gems/juicer
Then open `test/sinon-dist.html` in a browser.

@@ -60,0 +67,0 @@

@@ -6,3 +6,2 @@ require("../sinon_test.js");

require("../sinon/mock_test.js");
require("../sinon/util/fake_timers_test.js");
require("../sinon/collection_test.js");

@@ -16,2 +15,20 @@ require("../sinon/sandbox_test.js");

var args = process.argv.slice(2);
while (args.length) {
switch (args.shift()) {
case "-h":
case "--help":
console.log("Usage: node test/node/run.js [-u]");
console.log(" -u, --unstable Enable unstable tests");
console.log(" -h, --help This cruft");
process.exit(1);
break;
case "-u":
case "--unstable":
require("../sinon/util/fake_timers_test.js");
break;
}
}
buster.testRunner.onCreate(function (runner) {

@@ -18,0 +35,0 @@ runner.on("suite:end", function (results) {

@@ -11,3 +11,3 @@ /**

assertions: require("buster-assertions"),
format: require("buster-format"),
format: require("formatio"),
eventedLogger: require("buster-evented-logger")

@@ -14,0 +14,0 @@ });

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

"originating stack traces": {
setUp: function () {
this.oldError = Error;
this.oldTypeError = TypeError;
var i = 0;
Error = TypeError = function () {
this.stack = ':STACK' + ++i + ':';
}
},
tearDown: function () {
Error = this.oldError;
TypeError = this.oldTypeError;
},
"throws with stack trace showing original wrapMethod call": function () {
var object = { method: function () {} };
sinon.wrapMethod(object, "method", function () { return 'original' });
try {
sinon.wrapMethod(object, "method", function () {});
} catch(e) {
assert.equals(e.stack, ':STACK2:\n--------------\n:STACK1:');
}
}
},
"in browser": {

@@ -235,2 +263,22 @@ requiresSupportFor: {

"passes equal arrays with custom properties": function () {
var arr1 = [1, 2, 3, "hey", "there"];
var arr2 = [1, 2, 3, "hey", "there"];
arr1.foo = "bar";
arr2.foo = "bar";
assert(sinon.deepEqual(arr1, arr2));
},
"fails arrays with unequal custom properties": function () {
var arr1 = [1, 2, 3, "hey", "there"];
var arr2 = [1, 2, 3, "hey", "there"];
arr1.foo = "bar";
arr2.foo = "not bar";
assert.isFalse(sinon.deepEqual(arr1, arr2));
},
"passes equal objects": function () {

@@ -409,3 +457,3 @@ var obj1 = { a: 1, b: 2, c: 3, d: "hey", e: "there" };

"format": {
"formats with buster by default": function () {
"formats with formatio by default": function () {
assert.equals(sinon.format({ id: 42 }), "{ id: 42 }");

@@ -495,3 +543,3 @@ },

var TYPE = "some-value";
var Class = function() {}
var Class = function() {};
Class.prototype.type = TYPE;

@@ -498,0 +546,0 @@

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

this.customPrototype = this.CustomConstructor.prototype;
this.StubConstructor = sinon.spy(this, "CustomConstructor");
sinon.spy(this, "CustomConstructor");
},

@@ -1215,3 +1215,3 @@

"calls" : {
oneLine : function () {
"oneLine" : function () {
function test(arg, expected) {

@@ -1234,3 +1234,3 @@ var spy = sinon.spy();

},
multiline : function () {
"multiline" : function () {
var str = 'spy\ntest';

@@ -1237,0 +1237,0 @@ var spy = sinon.spy();

@@ -492,2 +492,17 @@ /*jslint onevar: false*/

});
},
"works with sinon matchers": function(){
this.expectation.withArgs(sinon.match.number, sinon.match.string, sinon.match.func);
this.expectation(1, "test", function(){});
assert(this.expectation.met());
},
"throws when sinon matchers fail": function(){
var expectation = this.expectation;
this.expectation.withArgs(sinon.match.number, sinon.match.string, sinon.match.func);
assert.exception(function () {
expectation(1, 2, 3);
}, "ExpectationError");
}

@@ -551,3 +566,3 @@ },

"nots allow excessive args with no expected args": function () {
"does not allow excessive args with no expected args": function () {
var expectation = this.expectation;

@@ -585,3 +600,3 @@ expectation.withExactArgs();

"verify": {
"passs if met": function () {
"pass if met": function () {
sinon.stub(sinon.expectation, "pass");

@@ -879,4 +894,4 @@ var expectation = this.expectation;

this.mock = sinon.mock.create(this.object);
this.mock1 = this.mock.expects("method");
this.mock2 = this.mock.expects("method").on(this.thisValue);
this.mock.expects("method");
this.mock.expects("method").on(this.thisValue);
},

@@ -969,3 +984,2 @@

var mock = sinon.mock().yields();
var spy = sinon.spy();

@@ -972,0 +986,0 @@ try {

@@ -300,2 +300,18 @@ /*jslint onevar: false*/

"does not inject properties if they are already present": function() {
var server = function(){},
clock = {},
spy = false,
object = { server: server, clock: clock, spy: spy};
sinon.sandbox.create(sinon.getConfig({
properties: ["server", "clock", "spy"],
injectInto: object
}));
assert.same(object.server, server);
assert.same(object.clock, clock);
assert.same(object.spy, spy);
},
"ajax options": {

@@ -374,3 +390,3 @@ requiresSupportFor: { "ajax/browser": supportsAjax },

"fakes specified timers": function () {
var sandbox = sinon.sandbox.create(sinon.getConfig({
sinon.sandbox.create(sinon.getConfig({
injectIntoThis: false,

@@ -377,0 +393,0 @@ properties: ["clock"],

@@ -1327,2 +1327,32 @@ /*jslint onevar: false, eqeqeq: false*/

"contains the created object for spied constructors": function () {
var spy = sinon.spy.create(function() { });
var result = new spy();
assert.equals(spy.returnValues[0], result);
},
"contains the return value for spied constructors that explicitly return objects": function () {
var spy = sinon.spy.create(function() {
return { isExplicitlyCreatedValue: true };
});
var result = new spy();
assert.isTrue(result.isExplicitlyCreatedValue);
assert.equals(spy.returnValues[0], result);
},
"contains the created object for spied constructors that explicitly return primitive values": function () {
var spy = sinon.spy.create(function() {
return 10;
});
var result = new spy();
refute.equals(result, 10);
assert.equals(spy.returnValues[0], result);
},
"stacks up return values": function () {

@@ -1459,2 +1489,12 @@ var calls = 0;

assert.same(spy.firstCall.spy, call0.spy);
},
"is tracked even if exceptions are thrown": function () {
var spy = sinon.spy(function () { throw "an exception"; });
try {
spy();
} catch (e) { }
refute.isNull(spy.firstCall);
}

@@ -1583,2 +1623,20 @@

"getCalls": {
"returns an empty Array by default": function () {
var spy = sinon.spy();
assert.isArray(spy.getCalls());
assert.equals(spy.getCalls().length, 0);
},
"is analogous to using getCall(n)": function () {
var spy = sinon.spy();
spy();
spy();
assert.equals(spy.getCalls(), [ spy.getCall(0), spy.getCall(1) ]);
}
},
"callArg": {

@@ -1920,3 +1978,3 @@ "is function": function () {

"passs additional arguments": function () {
"pass additional arguments": function () {
var spy = sinon.spy();

@@ -1923,0 +1981,0 @@ var callback = sinon.spy();

/*jslint onevar: false*/
/*globals sinon buster*/
/*globals sinon buster require assert*/
/**

@@ -25,3 +25,3 @@ * @author Christian Johansen (christian@cjohansen.no)

"should contain asynchronous versions of callsArg*, yields*, and thenYields methods": function() {
"should contain asynchronous versions of callsArg*, and yields* methods": function() {
var stub = sinon.stub.create();

@@ -33,3 +33,3 @@

for (var method in stub) {
if (stub.hasOwnProperty(method) && method.match(/^(callsArg|yields|thenYields$)/)) {
if (stub.hasOwnProperty(method) && method.match(/^(callsArg|yields)/)) {
if (!method.match(/Async/)) {

@@ -47,2 +47,13 @@ syncVersions++;

"should allow overriding async behavior with sync behavior": function() {
var stub = sinon.stub();
var callback = sinon.spy();
stub.callsArgAsync(1);
stub.callsArg(1);
stub(1, callback);
assert(callback.called);
},
"returns": {

@@ -480,3 +491,3 @@ "returns specified value": function () {

var result = sinon.stub(this.object, "method");
sinon.stub(this.object, "method");

@@ -546,3 +557,2 @@ assert.same(args[0], this.object);

var stub = sinon.stub(this.object, "method");
var someObj = {};
stub.throws("TypeError");

@@ -574,2 +584,12 @@

"successfully stubs falsey properties": function () {
var obj = { 0: function() { } };
sinon.stub(obj, 0, function () {
return "stubbed value";
});
assert.equals(obj[0](), "stubbed value");
},
"does not stub function object": function () {

@@ -590,3 +610,3 @@ assert.exception(function () {

var stub = sinon.stub(obj);
sinon.stub(obj);

@@ -603,3 +623,3 @@ assert.isFunction(obj.func1.restore);

var stub = sinon.stub(obj);
sinon.stub(obj);

@@ -733,3 +753,3 @@ assert.isFunction(obj.func1.restore);

stub(spy);
})
});
assert(spy.calledOnce);

@@ -1064,10 +1084,2 @@ },

"passes call to callsArg": function () {
var spy = sinon.spy(this.stub, "callsArg");
this.stub.callsArgAsync(2);
assert(spy.calledWith(2));
},
"asynchronously calls argument at specified index": function (done) {

@@ -1088,11 +1100,2 @@ this.stub.callsArgAsync(2);

"passes call to callsArgWith": function () {
var object = {};
sinon.spy(this.stub, "callsArgWith");
this.stub.callsArgWithAsync(1, object);
assert(this.stub.callsArgWith.calledWith(1, object));
},
"asynchronously calls callback at specified index with multiple args": function (done) {

@@ -1121,10 +1124,2 @@ var object = {};

"passes call to callsArgOn": function () {
sinon.spy(this.stub, "callsArgOn");
this.stub.callsArgOnAsync(2, this.fakeContext);
assert(this.stub.callsArgOn.calledWith(2, this.fakeContext));
},
"asynchronously calls argument at specified index with specified context": function (done) {

@@ -1150,11 +1145,2 @@ var context = this.fakeContext;

"passes call to callsArgOnWith": function () {
var object = {};
sinon.spy(this.stub, "callsArgOnWith");
this.stub.callsArgOnWithAsync(1, this.fakeContext, object);
assert(this.stub.callsArgOnWith.calledWith(1, this.fakeContext, object));
},
"asynchronously calls argument at specified index with provided context and args": function (done) {

@@ -1166,3 +1152,3 @@ var object = {};

var callback = sinon.spy(done(function () {
assert(callback.calledOn(context))
assert(callback.calledOn(context));
assert(callback.calledWith(object));

@@ -1178,11 +1164,2 @@ }));

"yieldsAsync": {
"passes call to yields": function () {
var stub = sinon.stub();
sinon.spy(stub, "yields");
stub.yieldsAsync();
assert(stub.yields.calledWith());
},
"asynchronously invokes only argument as callback": function (done) {

@@ -1205,11 +1182,2 @@ var stub = sinon.stub().yieldsAsync();

"passes call to yieldsOn": function () {
var stub = sinon.stub();
sinon.spy(stub, "yieldsOn");
stub.yieldsOnAsync(this.fakeContext);
assert(stub.yieldsOn.calledWith(this.fakeContext));
},
"asynchronously invokes only argument as callback with given context": function (done) {

@@ -1232,11 +1200,2 @@ var context = this.fakeContext;

"yieldsToAsync": {
"passes call to yieldsTo": function () {
var stub = sinon.stub();
sinon.spy(stub, "yieldsTo");
stub.yieldsToAsync("success");
assert(stub.yieldsTo.calledWith("success"));
},
"asynchronously yields to property of object argument": function (done) {

@@ -1262,11 +1221,2 @@ var stub = sinon.stub().yieldsToAsync("success");

"passes call to yieldsToOn": function () {
var stub = sinon.stub();
sinon.spy(stub, "yieldsToOn");
stub.yieldsToOnAsync("success", this.fakeContext);
assert(stub.yieldsToOn.calledWith("success", this.fakeContext));
},
"asynchronously yields to property of object argument with given context": function (done) {

@@ -1283,3 +1233,2 @@ var context = this.fakeContext;

this.stub({ success: callback });
assert(!callback.called);

@@ -1289,134 +1238,257 @@ }

"yields* calls should be chainable to produce a sequence": function () {
var context = { foo: "bar" };
var obj = { method1: sinon.spy(), method2: sinon.spy() };
var obj2 = { method2: sinon.spy() };
var stub = sinon.stub().yields(1, 2)
.yieldsOn(context, 3, 4)
.yieldsTo("method1", 5, 6)
.yieldsToOn("method2", context, 7, 8);
"onCall": {
"can be used with returns to produce sequence": function() {
var stub = sinon.stub().returns(3);
stub.onFirstCall().returns(1)
.onCall(2).returns(2);
var spy1 = sinon.spy();
var spy2 = sinon.spy();
assert.same(stub(), 1);
assert.same(stub(), 3);
assert.same(stub(), 2);
assert.same(stub(), 3);
},
stub(spy1);
stub(spy2);
stub(obj);
stub(obj);
stub(obj2); // should continue doing the last thing
"can be used with returnsArg to produce sequence": function() {
var stub = sinon.stub().returns('default');
stub.onSecondCall().returnsArg(0);
assert(spy1.calledOnce);
assert(spy1.calledWithExactly(1, 2));
assert.same(stub(1), 'default');
assert.same(stub(2), 2);
assert.same(stub(3), 'default');
},
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert(spy2.calledOn(context));
assert(spy2.calledWithExactly(3, 4));
"can be used with returnsThis to produce sequence": function() {
var instance = {};
instance.stub = sinon.stub().returns('default');
instance.stub.onSecondCall().returnsThis();
assert(obj.method1.calledOnce);
assert(obj.method1.calledAfter(spy2));
assert(obj.method1.calledWithExactly(5, 6));
assert.same(instance.stub(), 'default');
assert.same(instance.stub(), instance);
assert.same(instance.stub(), 'default');
},
assert(obj.method2.calledOnce);
assert(obj.method2.calledAfter(obj.method1));
assert(obj.method2.calledOn(context));
assert(obj.method2.calledWithExactly(7, 8));
"can be used with throwsException to produce sequence": function() {
var stub = sinon.stub();
var error = new Error();
stub.onSecondCall().throwsException(error);
assert(obj2.method2.calledOnce);
assert(obj2.method2.calledAfter(obj.method2));
assert(obj2.method2.calledOn(context));
assert(obj2.method2.calledWithExactly(7, 8));
},
stub();
try {
stub();
fail("Expected stub to throw");
} catch (e) {
assert.same(e, error);
}
},
"callsArg* calls should be chainable to produce a sequence": function () {
var spy1 = sinon.spy();
var spy2 = sinon.spy();
var spy3 = sinon.spy();
var spy4 = sinon.spy();
var spy5 = sinon.spy();
var decoy = sinon.spy();
var context = { foo: "bar" };
"in combination with withArgs": {
"can produce a sequence for a fake": function() {
var stub = sinon.stub().returns(0);
stub.withArgs(5).returns(-1)
.onFirstCall().returns(1)
.onSecondCall().returns(2);
var stub = sinon.stub().callsArg(0)
.callsArgWith(1, "a", "b")
.callsArgOn(2, context)
.callsArgOnWith(3, context, "c", "d");
assert.same(stub(0), 0);
assert.same(stub(5), 1);
assert.same(stub(0), 0);
assert.same(stub(5), 2);
assert.same(stub(5), -1);
},
stub(spy1);
stub(decoy, spy2);
stub(decoy, decoy, spy3);
stub(decoy, decoy, decoy, spy4);
stub(decoy, decoy, decoy, spy5); // should continue doing last thing
"falls back to stub default behaviour if fake does not have its own default behaviour": function() {
var stub = sinon.stub().returns(0);
stub.withArgs(5)
.onFirstCall().returns(1);
assert(spy1.calledOnce);
assert.same(stub(5), 1);
assert.same(stub(5), 0);
},
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert(spy2.calledWithExactly("a", "b"));
"falls back to stub behaviour for call if fake does not have its own behaviour for call": function() {
var stub = sinon.stub().returns(0);
stub.withArgs(5).onFirstCall().returns(1);
stub.onSecondCall().returns(2);
assert(spy3.calledOnce);
assert(spy3.calledAfter(spy2));
assert(spy3.calledOn(context));
assert.same(stub(5), 1);
assert.same(stub(5), 2);
assert.same(stub(4), 0);
},
assert(spy4.calledOnce);
assert(spy4.calledAfter(spy3));
assert(spy4.calledOn(context));
assert(spy4.calledWithExactly("c", "d"));
"defaults to undefined behaviour once no more calls have been defined": function() {
var stub = sinon.stub();
stub.withArgs(5).onFirstCall().returns(1)
.onSecondCall().returns(2);
assert(spy5.calledOnce);
assert(spy5.calledAfter(spy4));
assert(spy5.calledOn(context));
assert(spy5.calledWithExactly("c", "d"));
assert.same(stub(5), 1);
assert.same(stub(5), 2);
refute.defined(stub(5));
},
assert(decoy.notCalled);
},
"does not create undefined behaviour just by calling onCall": function() {
var stub = sinon.stub().returns(2);
stub.onFirstCall();
"yields* calls and callsArg* in combination should be chainable to produce a sequence": function () {
var stub = sinon.stub().yields(1, 2)
.callsArg(1)
.yieldsTo("method")
.callsArgWith(2, "a", "b");
assert.same(stub(6), 2);
},
var obj = { method: sinon.spy() };
var spy1 = sinon.spy();
var spy2 = sinon.spy();
var spy3 = sinon.spy();
var decoy = sinon.spy();
"works with fakes and reset": function() {
var stub = sinon.stub();
stub.withArgs(5).onFirstCall().returns(1);
stub.withArgs(5).onSecondCall().returns(2);
stub(spy1);
stub(decoy, spy2);
stub(obj);
stub(decoy, decoy, spy3);
assert.same(stub(5), 1);
assert.same(stub(5), 2);
refute.defined(stub(5));
assert(spy1.calledOnce);
stub.reset();
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert.same(stub(5), 1);
assert.same(stub(5), 2);
refute.defined(stub(5));
},
assert(obj.method.calledOnce);
assert(obj.method.calledAfter(spy2));
"throws an understandable error when trying to use withArgs on behavior": function() {
try {
sinon.stub().onFirstCall().withArgs(1);
} catch (e) {
assert.match(e.message, /not supported/);
}
}
},
assert(spy3.calledOnce);
assert(spy3.calledAfter(obj.method));
assert(spy3.calledWithExactly("a", "b"));
"can be used with yields* to produce a sequence": function () {
var context = { foo: "bar" };
var obj = { method1: sinon.spy(), method2: sinon.spy() };
var obj2 = { method2: sinon.spy() };
var stub = sinon.stub().yieldsToOn("method2", context, 7, 8);
stub.onFirstCall().yields(1, 2)
.onSecondCall().yieldsOn(context, 3, 4)
.onThirdCall().yieldsTo("method1", 5, 6)
.onCall(3).yieldsToOn("method2", context, 7, 8);
assert(decoy.notCalled);
},
var spy1 = sinon.spy();
var spy2 = sinon.spy();
"callsArgWith sequences should interact correctly with assertions (GH-231)": function () {
var stub = sinon.stub();
var spy = sinon.spy();
stub(spy1);
stub(spy2);
stub(obj);
stub(obj);
stub(obj2); // should continue with default behavior
stub.callsArgWith(0, "a");
assert(spy1.calledOnce);
assert(spy1.calledWithExactly(1, 2));
stub(spy);
assert(spy.calledWith("a"));
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert(spy2.calledOn(context));
assert(spy2.calledWithExactly(3, 4));
stub(spy);
assert(spy.calledWith("a"));
assert(obj.method1.calledOnce);
assert(obj.method1.calledAfter(spy2));
assert(obj.method1.calledWithExactly(5, 6));
stub.callsArgWith(0, "b");
assert(obj.method2.calledOnce);
assert(obj.method2.calledAfter(obj.method1));
assert(obj.method2.calledOn(context));
assert(obj.method2.calledWithExactly(7, 8));
stub(spy);
assert(spy.calledWith("b"));
assert(obj2.method2.calledOnce);
assert(obj2.method2.calledAfter(obj.method2));
assert(obj2.method2.calledOn(context));
assert(obj2.method2.calledWithExactly(7, 8));
},
"can be used with callsArg* to produce a sequence": function () {
var spy1 = sinon.spy();
var spy2 = sinon.spy();
var spy3 = sinon.spy();
var spy4 = sinon.spy();
var spy5 = sinon.spy();
var decoy = sinon.spy();
var context = { foo: "bar" };
var stub = sinon.stub().callsArgOnWith(3, context, "c", "d");
stub.onFirstCall().callsArg(0)
.onSecondCall().callsArgWith(1, "a", "b")
.onThirdCall().callsArgOn(2, context)
.onCall(3).callsArgOnWith(3, context, "c", "d");
stub(spy1);
stub(decoy, spy2);
stub(decoy, decoy, spy3);
stub(decoy, decoy, decoy, spy4);
stub(decoy, decoy, decoy, spy5); // should continue with default behavior
assert(spy1.calledOnce);
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert(spy2.calledWithExactly("a", "b"));
assert(spy3.calledOnce);
assert(spy3.calledAfter(spy2));
assert(spy3.calledOn(context));
assert(spy4.calledOnce);
assert(spy4.calledAfter(spy3));
assert(spy4.calledOn(context));
assert(spy4.calledWithExactly("c", "d"));
assert(spy5.calledOnce);
assert(spy5.calledAfter(spy4));
assert(spy5.calledOn(context));
assert(spy5.calledWithExactly("c", "d"));
assert(decoy.notCalled);
},
"can be used with yields* and callsArg* in combination to produce a sequence": function () {
var stub = sinon.stub().yields(1, 2);
stub.onSecondCall().callsArg(1)
.onThirdCall().yieldsTo("method")
.onCall(3).callsArgWith(2, "a", "b");
var obj = { method: sinon.spy() };
var spy1 = sinon.spy();
var spy2 = sinon.spy();
var spy3 = sinon.spy();
var decoy = sinon.spy();
stub(spy1);
stub(decoy, spy2);
stub(obj);
stub(decoy, decoy, spy3);
assert(spy1.calledOnce);
assert(spy2.calledOnce);
assert(spy2.calledAfter(spy1));
assert(obj.method.calledOnce);
assert(obj.method.calledAfter(spy2));
assert(spy3.calledOnce);
assert(spy3.calledAfter(obj.method));
assert(spy3.calledWithExactly("a", "b"));
assert(decoy.notCalled);
},
"should interact correctly with assertions (GH-231)": function () {
var stub = sinon.stub();
var spy = sinon.spy();
stub.callsArgWith(0, "a");
stub(spy);
assert(spy.calledWith("a"));
stub(spy);
assert(spy.calledWith("a"));
stub.onThirdCall().callsArgWith(0, "b");
stub(spy);
assert(spy.calledWith("b"));
}
},

@@ -1438,4 +1510,4 @@

"clears yields* and callsArg* sequence": function () {
var stub = sinon.stub().yields(1)
.callsArg(1);
var stub = sinon.stub().yields(1);
stub.onFirstCall().callsArg(1);
stub.resetBehavior();

@@ -1476,3 +1548,3 @@ stub.yields(3);

refute.defined(parentStub('lolz'));
assert.same(parentStub('lolz'), false);
assert.same(parentStub(), false);

@@ -1479,0 +1551,0 @@ },

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

var testCase = this.boundTestCase();
var obj = {};

@@ -397,2 +396,5 @@ sinon.config = {

clearTimeout: clearTimeout,
// clear & setImmediate are not yet available in all environments
setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined),
clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined),
setInterval: setInterval,

@@ -406,2 +408,4 @@ clearInterval: clearInterval

assert.same(props.clearTimeout, sinon.timers.clearTimeout);
assert.same(props.setImmediate, sinon.timers.setImmediate);
assert.same(props.clearImmediate, sinon.timers.clearImmediate);
assert.same(props.setInterval, sinon.timers.setInterval);

@@ -430,3 +434,2 @@ assert.same(props.clearInterval, sinon.timers.clearInterval);

var testCase = this.boundTestCase();
var obj = {};

@@ -444,3 +447,2 @@ sinon.test(testCase.fn).call(testCase);

var testCase = this.boundTestCase();
var obj = {};

@@ -447,0 +449,0 @@ sinon.config = {

@@ -161,2 +161,24 @@ /*jslint onevar: false, browser: false, regexp: false, browser: true*/

"does not respond to requests queued after respond() (eg from callbacks)": function () {
var xhr;
this.getRootAsync.addEventListener("load", function() {
xhr = new sinon.FakeXMLHttpRequest();
xhr.open("GET", "/", true);
xhr.send();
sinon.spy(xhr, "respond");
});
this.server.respondWith("Oh yeah! Duffman!");
this.server.respond();
assert(this.getRootAsync.respond.called);
assert(this.getPathAsync.respond.called);
assert(!xhr.respond.called);
this.server.respond();
assert(xhr.respond.called);
},
"responds with status, headers, and body": function () {

@@ -389,2 +411,12 @@ var headers = { "Content-Type": "X-test" };

assert.equals(this.postPathAsync.respond.args[0], [200, {}, "Oh yeah! Duffman!"]);
},
"responds to most recently defined match": function() {
this.server.respondWith("POST", "", "All POSTs");
this.server.respondWith("POST", "/path", "Particular POST");
this.server.respond();
assert.equals(this.postRootAsync.respond.args[0], [200, {}, "All POSTs"]);
assert.equals(this.postPathAsync.respond.args[0], [200, {}, "Particular POST"]);
}

@@ -443,2 +475,14 @@ },

"yields response to request function handler when url contains RegExp characters": function () {
var handler = sinon.spy();
this.server.respondWith("GET", "/hello?world", handler);
var xhr = new sinon.FakeXMLHttpRequest();
xhr.open("GET", "/hello?world");
xhr.send();
this.server.respond();
assert(handler.calledOnce);
},
"does not yield response to request function handler when method does not match": function () {

@@ -498,4 +542,4 @@ var handler = sinon.spy();

var handler = sinon.spy();
this.server.respondWith("GET", "/aloha", [200, {}, "Oh hi"]);
this.server.respondWith("GET", /\/a.*/, handler);
this.server.respondWith("GET", "/aloha", [200, {}, "Oh hi"]);
var xhr = new sinon.FakeXMLHttpRequest();

@@ -606,3 +650,3 @@ xhr.respond = sinon.spy();

sinon.spy(request, "respond");
request.open("get", "/path", true);
request.open("get", url, true);
request.send();

@@ -670,4 +714,37 @@ return request;

assert.isTrue(request.respond.calledOnce);
},
"auto-responds if two successive requests are made with a single XHR": function () {
this.server.autoRespond = true;
var request = this.get("/path");
this.clock.tick(10);
assert.isTrue(request.respond.calledOnce);
request.open("get", "/other", true);
request.send();
this.clock.tick(10);
assert.isTrue(request.respond.calledTwice);
},
"auto-responds if timeout elapses between creating a XHR object and sending a request with it": function () {
this.server.autoRespond = true;
var request = new sinon.FakeXMLHttpRequest();
sinon.spy(request, "respond");
this.clock.tick(100);
request.open("get", "/path", true);
request.send();
this.clock.tick(10);
assert.isTrue(request.respond.calledOnce);
}
}
});

@@ -12,65 +12,66 @@ /*jslint onevar: false, browser: false, regexp: false, browser: true*/

buster.testCase("sinon.fakeServerWithClock", {
setUp: function () {
this.server = sinon.fakeServerWithClock.create();
},
"without pre-existing fake clock": {
setUp: function () {
this.server = sinon.fakeServerWithClock.create();
},
tearDown: function () {
this.server.restore();
if (this.clock) { this.clock.restore(); }
},
tearDown: function () {
this.server.restore();
if (this.clock) { this.clock.restore(); }
},
"calls 'super' when adding requests": sinon.test(function () {
var addRequest = this.stub(sinon.fakeServer, "addRequest");
var xhr = {};
this.server.addRequest(xhr);
"calls 'super' when adding requests": sinon.test(function () {
var addRequest = this.stub(sinon.fakeServer, "addRequest");
var xhr = {};
this.server.addRequest(xhr);
assert(addRequest.calledWith(xhr));
assert(addRequest.calledOn(this.server));
}),
assert(addRequest.calledWith(xhr));
assert(addRequest.calledOn(this.server));
}),
"sets reference to clock when adding async request": function () {
this.server.addRequest({ async: true });
"sets reference to clock when adding async request": function () {
this.server.addRequest({ async: true });
assert.isObject(this.server.clock);
assert.isFunction(this.server.clock.tick);
},
assert.isObject(this.server.clock);
assert.isFunction(this.server.clock.tick);
},
"sets longest timeout from setTimeout": function () {
this.server.addRequest({ async: true });
"sets longest timeout from setTimeout": function () {
this.server.addRequest({ async: true });
setTimeout(function () {}, 12);
setTimeout(function () {}, 29);
setInterval(function () {}, 12);
setTimeout(function () {}, 27);
setTimeout(function () {}, 12);
setTimeout(function () {}, 29);
setInterval(function () {}, 12);
setTimeout(function () {}, 27);
assert.equals(this.server.longestTimeout, 29);
},
assert.equals(this.server.longestTimeout, 29);
},
"sets longest timeout from setInterval": function () {
this.server.addRequest({ async: true });
"sets longest timeout from setInterval": function () {
this.server.addRequest({ async: true });
setTimeout(function () {}, 12);
setTimeout(function () {}, 29);
setInterval(function () {}, 132);
setTimeout(function () {}, 27);
setTimeout(function () {}, 12);
setTimeout(function () {}, 29);
setInterval(function () {}, 132);
setTimeout(function () {}, 27);
assert.equals(this.server.longestTimeout, 132);
},
assert.equals(this.server.longestTimeout, 132);
},
"resets clock": function () {
this.server.addRequest({ async: true });
"resets clock": function () {
this.server.addRequest({ async: true });
this.server.respond("");
this.server.respond("");
assert.same(setTimeout, sinon.timers.setTimeout);
},
assert.same(setTimeout, sinon.timers.setTimeout);
},
"does not reset clock second time": function () {
this.server.addRequest({ async: true });
this.server.respond("");
this.clock = sinon.useFakeTimers();
this.server.addRequest({ async: true });
this.server.respond("");
"does not reset clock second time": function () {
this.server.addRequest({ async: true });
this.server.respond("");
this.clock = sinon.useFakeTimers();
this.server.addRequest({ async: true });
this.server.respond("");
refute.same(setTimeout, sinon.timers.setTimeout);
refute.same(setTimeout, sinon.timers.setTimeout);
}
},

@@ -77,0 +78,0 @@

@@ -17,2 +17,4 @@ /*jslint onevar: false, eqeqeq: false, plusplus: false*/

var globalDate = Date;
buster.testCase("sinon.clock", {

@@ -96,2 +98,69 @@ setUp: function () {

"setImmediate": {
setUp: function () {
this.clock = sinon.clock.create();
},
"returns numeric id": function () {
var result = this.clock.setImmediate(function () { });
assert.isNumber(result);
},
"calls the given callback immediately": function () {
var stub = sinon.stub.create();
this.clock.setImmediate(stub);
this.clock.tick(0);
assert(stub.called);
},
"throws if no arguments": function () {
var clock = this.clock;
assert.exception(function () {
clock.setImmediate();
});
},
"manages separate timers per clock instance": function () {
var clock1 = sinon.clock.create();
var clock2 = sinon.clock.create();
var stubs = [sinon.stub.create(), sinon.stub.create()];
clock1.setImmediate(stubs[0]);
clock2.setImmediate(stubs[1]);
clock2.tick(0);
assert.isFalse(stubs[0].called);
assert(stubs[1].called);
},
"passes extra parameters through to the callback": function () {
var stub = sinon.stub.create();
this.clock.setImmediate(stub, 'value1', 2);
this.clock.tick(1);
assert(stub.calledWithExactly('value1', 2));
}
},
"clearImmediate": {
setUp: function () {
this.clock = sinon.clock.create();
},
"removes immediate callbacks": function () {
var callback = sinon.stub.create();
var id = this.clock.setImmediate(callback);
this.clock.clearImmediate(id);
this.clock.tick(1);
assert.isFalse(callback.called);
}
},
"tick": {

@@ -157,2 +226,23 @@ setUp: function () {

"triggers multiple simultaneous timers with zero callAt": function () {
var test = this;
var spies = [
sinon.spy(function() {
test.clock.setTimeout(spies[1], 0)
}),
sinon.spy(),
sinon.spy()
];
// First spy calls another setTimeout with delay=0
this.clock.setTimeout(spies[0], 0);
this.clock.setTimeout(spies[2], 10);
this.clock.tick(10);
assert(spies[0].called);
assert(spies[1].called);
assert(spies[2].called);
},
"waits after setTimeout was called": function () {

@@ -443,3 +533,3 @@ this.clock.tick(100);

"terval": {
"setInterval": {
setUp: function () {

@@ -507,3 +597,3 @@ this.clock = sinon.clock.create();

setUp: function () {
this.now = new Date().getTime() - 3000;
this.now = new globalDate().getTime() - 3000;
this.clock = sinon.clock.create(this.now);

@@ -697,3 +787,2 @@ this.Date = this.global.Date;

"toSource": {

@@ -745,3 +834,3 @@ requiresSupportFor: { "Date.toSource": !!Date.toSource },

"haves clock property": function () {
"has clock property": function () {
this.clock = sinon.useFakeTimers();

@@ -851,24 +940,27 @@

"//deletes global property if it originally did not have own property":
"Not quite sure why this test was initially commented out - TODO: Fix"
/*function () {
// remove this properties from the global object ("hasOwnProperty" false)
// delete this.global.clearTimeout;
// delete this.global.setInterval;
// // set these properties to the global object ("hasOwnProperty" true)
// this.global.clearInterval = this.global.clearInterval;
// this.global.setTimeout = this.global.clearInterval;
"deletes global property on restore if it was inherited onto the global object": function () {
// Give the global object an inherited 'tick' method
delete this.global.tick;
this.global.__proto__.tick = function() { };
// this.clock = sinon.useFakeTimers();
// this.clock.restore();
this.clock = sinon.useFakeTimers('tick');
assert.isTrue(this.global.hasOwnProperty("tick"));
this.clock.restore();
// // these properties should be removed from the global object directly.
// assert.isFalse(this.global.hasOwnProperty("clearTimeout"));
// assert.isFalse(this.global.hasOwnProperty("setInterval"));
assert.isFalse(this.global.hasOwnProperty("tick"));
delete this.global.__proto__.tick;
},
// // these properties should be added back into the global object directly.
// assert(this.global.hasOwnProperty("clearInterval"));
// assert(this.global.hasOwnProperty("setTimeout"));
}*/,
"restores global property on restore if it is present on the global object itself": function () {
// Directly give the global object a tick method
this.global.tick = function () { };
this.clock = sinon.useFakeTimers('tick');
assert.isTrue(this.global.hasOwnProperty("tick"));
this.clock.restore();
assert.isTrue(this.global.hasOwnProperty("tick"));
delete this.global.tick;
},
"fakes Date constructor": function () {

@@ -903,2 +995,10 @@ this.clock = sinon.useFakeTimers(0);

"mirrors custom Date properties": function () {
var f = function () { };
this.global.Date.format = f;
sinon.useFakeTimers();
assert.equals(Date.format, f);
},
"restores Date constructor": function () {

@@ -908,3 +1008,3 @@ this.clock = sinon.useFakeTimers(0);

assert.same(Date, sinon.timers.Date);
assert.same(globalDate, sinon.timers.Date);
},

@@ -911,0 +1011,0 @@

@@ -70,2 +70,13 @@ /*jslint onevar: false, eqeqeq: false, browser: true*/

"withCredentials": {
setUp: function () {
this.xhr = new sinon.FakeXMLHttpRequest();
},
"property is set if we support standards CORS": function () {
assert.equals(sinon.xhr.supportsCORS, "withCredentials" in this.xhr);
}
},
"open": {

@@ -88,2 +99,3 @@ setUp: function () {

assert.equals(this.xhr.password, "pass");
},

@@ -631,8 +643,5 @@

"fire onload event": function () {
var fireOnLoad = false;
this.onload = function(){
fireOnLoad = true;
}
this.onload = this.spy;
this.xhr.respond(200, {}, "");
assert.isTrue(fireOnLoad);
assert.equals(this.spy.callCount, 1);
},

@@ -821,9 +830,6 @@

"fire onerror event": function () {
var testFlag = false,
this.onerror = function(){
testFlag = true;
};
this.xhr.aborted = true;
var spy = sinon.spy();
this.xhr.onerror = spy;
this.xhr.abort();
assert.isTrue(testFlag);
assert.equals(spy.callCount, 1);
},

@@ -1094,3 +1100,3 @@

"calls legacy onreadystatechange handlers": function () {
"calls legacy onreadystatechange handlers with target set to fakeXHR": function () {
var workingXHRInstance;

@@ -1107,2 +1113,3 @@ var spy;

var fakeXhr = this.fakeXhr;
runWithWorkingXHROveride(workingXHROverride, function () {

@@ -1113,2 +1120,6 @@ sinon.FakeXMLHttpRequest.defake(fakeXhr, []);

assert(spy.calledOnce);
// Fix to make weinre work
assert.isObject(spy.args[0][0]);
assert.equals(spy.args[0][0].target, fakeXhr);
});

@@ -1418,4 +1429,77 @@ },

}
},
"xhr.upload": {
setUp: function () {
this.xhr = new sinon.FakeXMLHttpRequest();
this.xhr.open("POST", "/some/url", true);
},
"progress event is triggered with xhr.uploadProgress({loaded: 20, total: 100})": function (done) {
this.xhr.upload.addEventListener("progress", function(e) {
assert.equals(e.total, 100);
assert.equals(e.loaded, 20);
done();
});
this.xhr.uploadProgress({
total: 100,
loaded: 20
});
},
"triggers 'load' event on success": function (done) {
var xhr = this.xhr;
this.xhr.upload.addEventListener("load", function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.DONE);
refute.equals(xhr.status, 0);
done();
});
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"fires event with 100% progress on 'load'": function(done) {
this.xhr.upload.addEventListener("progress", function(e) {
assert.equals(e.total, 100);
assert.equals(e.loaded, 100);
done();
});
this.xhr.send();
this.xhr.respond(200, {}, "");
},
"calls 'abort' on cancel": function (done) {
var xhr = this.xhr;
this.xhr.upload.addEventListener("abort", function () {
assert.equals(xhr.readyState, sinon.FakeXMLHttpRequest.UNSENT);
assert.equals(xhr.status, 0);
done();
});
this.xhr.send();
this.xhr.abort();
},
"error event is triggered with xhr.uploadError(new Error('foobar'))": function(done) {
this.xhr.upload.addEventListener("error", function(e) {
assert.equals(e.detail.message, "foobar");
done();
});
this.xhr.uploadError(new Error("foobar"));
},
"event listeners can be removed": function() {
var callback = function() {};
this.xhr.upload.addEventListener("load", callback);
this.xhr.upload.removeEventListener("load", callback);
assert.equals(this.xhr.upload.eventListeners["load"].length, 0);
}
}
});
}(this));

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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