Comparing version 1.1.1 to 1.2.0
@@ -0,1 +1,24 @@ | ||
== 1.2.0 / 2011-09-27 | ||
* Bug fix: abort() switches state to DONE when OPENED and sent. Fix by | ||
Tristan Koch. | ||
* Bug fix: Mootools uses MSXML2.XMLHTTP as objectId, which Sinon matched with | ||
different casing. Fix by Olmo Maldonado. | ||
* Bug fix: When wrapping a non-owned property, restore now removes the wrapper | ||
instead of replacing it. Fix by Will Butler. | ||
* Bug fix: Make it possibly to stub Array.prototype.push by not using that | ||
method directly inside Sinon. | ||
* Bug fix: Don't assume that req.requestBody is a string in the fake server. | ||
* Added spy.printf(format) to print a nicely formatted message with details | ||
about a spy. | ||
* Garbage collection: removing fakes from collections when restoring the | ||
original methods. Fix by Tristan Koch. | ||
* Add spy.calledWithNew to check if a function was used as a constructor | ||
* Add spy.notCalledWith(), spy.neverCalledWith() and | ||
sinon.assert.neverCalledWith. By Max Antoni | ||
* Publicly expose sinon.expectation.fail to allow tools to integrate with mock | ||
expectations. | ||
* Fake XMLHttpRequests now support a minimal portion of the events API, making | ||
them work seamlessly with e.g. SproutCode (which uses | ||
xhr.addEventListener("readystatechange"). Partially by Sven Fuchs. | ||
== 1.1.1 / 2011-05-17 | ||
@@ -61,6 +84,6 @@ * Fix broken mock verification in CommonJS when not including the full Sinon | ||
match previous behavior, through sinon.getConfig(sinon.config); | ||
The default configuration now lives in sinon.defaultConfig rather than the | ||
previous sinon.test. | ||
This change enables external tools, such as test framework adapters, to easily | ||
@@ -67,0 +90,0 @@ create configurable sandboxes without going through sinon.test |
@@ -64,2 +64,3 @@ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/ | ||
var owned = object.hasOwnProperty(property); | ||
object[property] = method; | ||
@@ -69,3 +70,7 @@ method.displayName = property; | ||
method.restore = function () { | ||
object[property] = wrappedMethod; | ||
if(owned) { | ||
object[property] = wrappedMethod; | ||
} else { | ||
delete object[property]; | ||
} | ||
}; | ||
@@ -150,14 +155,2 @@ | ||
keys: function keys(object) { | ||
var objectKeys = []; | ||
for (var prop in object) { | ||
if (object.hasOwnProperty(prop)) { | ||
objectKeys.push(prop); | ||
} | ||
} | ||
return objectKeys.sort(); | ||
}, | ||
functionName: function functionName(func) { | ||
@@ -220,2 +213,26 @@ var name = func.displayName || func.name; | ||
useFakeServer: true | ||
}, | ||
timesInWords: function timesInWords(count) { | ||
return count == 1 && "once" || | ||
count == 2 && "twice" || | ||
count == 3 && "thrice" || | ||
(count || 0) + " times"; | ||
}, | ||
calledInOrder: function (spies) { | ||
for (var i = 1, l = spies.length; i < l; i++) { | ||
if (!spies[i - 1].calledBefore(spies[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}, | ||
orderByFirstCall: function (spies) { | ||
return spies.sort(function (a, b) { | ||
// uuid, won't ever be equal | ||
return a.getCall(0).callId < b.getCall(0).callId ? -1 : 1; | ||
}); | ||
} | ||
@@ -222,0 +239,0 @@ }; |
@@ -23,3 +23,3 @@ /** | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -31,20 +31,19 @@ | ||
function times(count) { | ||
return count == 1 && "once" || | ||
count == 2 && "twice" || | ||
count == 3 && "thrice" || | ||
(count || 0) + " times"; | ||
} | ||
function verifyIsStub() { | ||
var method; | ||
function verifyIsStub(method) { | ||
if (!method) { | ||
assert.fail("fake is not a spy"); | ||
} | ||
for (var i = 0, l = arguments.length; i < l; ++i) { | ||
method = arguments[i]; | ||
if (typeof method != "function") { | ||
assert.fail(method + " is not a function"); | ||
} | ||
if (!method) { | ||
assert.fail("fake is not a spy"); | ||
} | ||
if (typeof method.getCall != "function") { | ||
assert.fail(method + " is not stubbed"); | ||
if (typeof method != "function") { | ||
assert.fail(method + " is not a function"); | ||
} | ||
if (typeof method.getCall != "function") { | ||
assert.fail(method + " is not stubbed"); | ||
} | ||
} | ||
@@ -58,30 +57,25 @@ } | ||
function mirrorAssertion(method, message) { | ||
assert[method] = function (fake) { | ||
function mirrorPropAsAssertion(name, method, message) { | ||
if (arguments.length == 2) { | ||
message = method; | ||
method = name; | ||
} | ||
assert[name] = function (fake) { | ||
verifyIsStub(fake); | ||
var failed = typeof fake[method] == "function" ? | ||
!fake[method].apply(fake, slice.call(arguments, 1)) : !fake[method]; | ||
var args = slice.call(arguments, 1); | ||
var failed = false; | ||
if (typeof method == "function") { | ||
failed = !method(fake); | ||
} else { | ||
failed = typeof fake[method] == "function" ? | ||
!fake[method].apply(fake, args) : !fake[method]; | ||
} | ||
if (failed) { | ||
var msg = message.replace("%c", times(fake.callCount)); | ||
msg = msg.replace("%n", fake + ""); | ||
msg = msg.replace("%C", function (m) { | ||
return formatSpyCalls(fake); | ||
}); | ||
msg = msg.replace("%t", function (m) { | ||
return formatThisValues(fake); | ||
}); | ||
msg = msg.replace("%*", [].slice.call(arguments, 1).join(", ")); | ||
for (var i = 0, l = arguments.length; i < l; i++) { | ||
msg = msg.replace("%" + i, arguments[i]); | ||
} | ||
failAssertion(this, msg); | ||
failAssertion(this, fake.printf.apply(fake, [message].concat(args))); | ||
} else { | ||
assert.pass(method); | ||
assert.pass(name); | ||
} | ||
@@ -91,22 +85,7 @@ }; | ||
function formatSpyCalls(spy) { | ||
var calls = []; | ||
function exposedName(prefix, prop) { | ||
return !prefix || /^fail/.test(prop) ? prop : | ||
prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1); | ||
}; | ||
for (var i = 0, l = spy.callCount; i < l; ++i) { | ||
calls.push(" " + spy.getCall(i).toString()); | ||
} | ||
return calls.length > 0 ? "\n" + calls.join("\n") : ""; | ||
} | ||
function formatThisValues(spy) { | ||
var objects = []; | ||
for (var i = 0, l = spy.callCount; i < l; ++i) { | ||
objects.push(sinon.format(spy.thisValues[i])); | ||
} | ||
return objects.join(", "); | ||
} | ||
assert = { | ||
@@ -124,59 +103,14 @@ failException: "AssertError", | ||
called: function assertCalled(method) { | ||
verifyIsStub(method); | ||
if (!method.called) { | ||
failAssertion(this, "expected " + method + | ||
" to have been called at least once but was never called"); | ||
} else { | ||
assert.pass("called"); | ||
} | ||
}, | ||
notCalled: function assertNotCalled(method) { | ||
verifyIsStub(method); | ||
if (method.called) { | ||
failAssertion( | ||
this, "expected " + method + " to not have been called but was " + | ||
"called " + times(method.callCount) + formatSpyCalls(method)); | ||
} else { | ||
assert.pass("notCalled"); | ||
} | ||
}, | ||
callOrder: function assertCallOrder() { | ||
verifyIsStub(arguments[0]); | ||
var expected = []; | ||
var actual = []; | ||
var failed = false; | ||
expected.push(arguments[0]); | ||
verifyIsStub.apply(null, arguments); | ||
var expected = "", actual = ""; | ||
for (var i = 1, l = arguments.length; i < l; i++) { | ||
verifyIsStub(arguments[i]); | ||
expected.push(arguments[i]); | ||
if (!arguments[i - 1].calledBefore(arguments[i])) { | ||
failed = true; | ||
} | ||
} | ||
if (failed) { | ||
actual = [].concat(expected).sort(function (a, b) { | ||
var aId = a.getCall(0).callId; | ||
var bId = b.getCall(0).callId; | ||
// uuid, won't ever be equal | ||
return aId < bId ? -1 : 1; | ||
}); | ||
var expectedStr, actualStr; | ||
if (!sinon.calledInOrder(arguments)) { | ||
try { | ||
expectedStr = expected.join(", "); | ||
actualStr = actual.join(", "); | ||
expected = [].join.call(arguments, ", "); | ||
actual = sinon.orderByFirstCall(slice.call(arguments)).join(", "); | ||
} catch (e) {} | ||
failAssertion(this, "expected " + (expectedStr || "") + " to be " + | ||
"called in order but were called as " + actualStr); | ||
failAssertion(this, "expected " + expected + " to be " + | ||
"called in order but were called as " + actual); | ||
} else { | ||
@@ -191,5 +125,5 @@ assert.pass("callOrder"); | ||
if (method.callCount != count) { | ||
failAssertion(this, "expected " + method + " to be called " + | ||
times(count) + " but was called " + | ||
times(method.callCount) + formatSpyCalls(method)); | ||
var msg = "expected %n to be called " + sinon.timesInWords(count) + | ||
" but was called %c%C"; | ||
failAssertion(this, method.printf(msg)); | ||
} else { | ||
@@ -205,24 +139,12 @@ assert.pass("callCount"); | ||
options = options || {}; | ||
var prefix = typeof options.prefix == "undefined" && "assert" || options.prefix; | ||
var o = options || {}; | ||
var prefix = typeof o.prefix == "undefined" && "assert" || o.prefix; | ||
var includeFail = typeof o.includeFail == "undefined" || !!o.includeFail; | ||
var name = function (prop) { | ||
if (!prefix) { | ||
return prop; | ||
for (var method in this) { | ||
if (method != "export" && (includeFail || !/^(fail)/.test(method))) { | ||
target[exposedName(prefix, method)] = this[method]; | ||
} | ||
return prefix + prop.substring(0, 1).toUpperCase() + prop.substring(1); | ||
}; | ||
for (var assertion in this) { | ||
if (!/^(fail|expose)/.test(assertion)) { | ||
target[name(assertion)] = this[assertion]; | ||
} | ||
} | ||
if (typeof options.includeFail == "undefined" || !!options.includeFail) { | ||
target.fail = this.fail; | ||
target.failException = this.failException; | ||
} | ||
return target; | ||
@@ -232,13 +154,17 @@ } | ||
mirrorAssertion("calledOnce", "expected %n to be called once but was called %c%C"); | ||
mirrorAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); | ||
mirrorAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); | ||
mirrorAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); | ||
mirrorAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t"); | ||
mirrorAssertion("calledWith", "expected %n to be called with arguments %*%C"); | ||
mirrorAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); | ||
mirrorAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); | ||
mirrorAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); | ||
mirrorAssertion("threw", "%n did not throw exception%C"); | ||
mirrorAssertion("alwaysThrew", "%n did not always throw exception%C"); | ||
mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); | ||
mirrorPropAsAssertion("notCalled", function (spy) { return !spy.called; }, | ||
"expected %n to not have been called but was called %c%C"); | ||
mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); | ||
mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); | ||
mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); | ||
mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); | ||
mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t"); | ||
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C"); | ||
mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C"); | ||
mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C"); | ||
mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C"); | ||
mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C"); | ||
mirrorPropAsAssertion("threw", "%n did not throw exception%C"); | ||
mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C"); | ||
@@ -245,0 +171,0 @@ if (commonJSModule) { |
@@ -20,5 +20,6 @@ /** | ||
var commonJSModule = typeof module == "object" && typeof require == "function"; | ||
var push = [].push; | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -48,2 +49,10 @@ | ||
function compact(fakeCollection) { | ||
var fakes = getFakes(fakeCollection); | ||
var i = 0; | ||
while (i < fakes.length) { | ||
fakes.splice(i, 1); | ||
} | ||
} | ||
var collection = { | ||
@@ -56,2 +65,3 @@ verify: function resolve() { | ||
each(this, "restore"); | ||
compact(this); | ||
}, | ||
@@ -76,4 +86,3 @@ | ||
add: function add(fake) { | ||
getFakes(this).push(fake); | ||
push.call(getFakes(this), fake); | ||
return fake; | ||
@@ -80,0 +89,0 @@ }, |
@@ -19,5 +19,6 @@ /** | ||
var commonJSModule = typeof module == "object" && typeof require == "function"; | ||
var push = [].push; | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -81,7 +82,7 @@ | ||
this.proxies.push(method); | ||
push.call(this.proxies, method); | ||
} | ||
var expectation = sinon.expectation.create(method); | ||
this.expectations[method].push(expectation); | ||
push.call(this.expectations[method], expectation); | ||
@@ -108,5 +109,5 @@ return expectation; | ||
if (!expectation.met()) { | ||
messages.push(expectation.toString()); | ||
push.call(messages, expectation.toString()); | ||
} else { | ||
met.push(expectation.toString()); | ||
push.call(met, expectation.toString()); | ||
} | ||
@@ -119,3 +120,3 @@ }); | ||
if (messages.length > 0) { | ||
err(messages.concat(met).join("\n")); | ||
sinon.expectation.fail(messages.concat(met).join("\n")); | ||
} | ||
@@ -140,3 +141,3 @@ | ||
for (i = 0; i < length; i += 1) { | ||
messages.push(" " + expectations[i].toString()); | ||
push.call(messages, " " + expectations[i].toString()); | ||
} | ||
@@ -149,3 +150,3 @@ | ||
err(messages.join("\n")); | ||
sinon.expectation.fail(messages.join("\n")); | ||
} | ||
@@ -155,9 +156,4 @@ }; | ||
function err(message) { | ||
var exception = new Error(message); | ||
exception.name = "ExpectationError"; | ||
var times = sinon.timesInWords; | ||
throw exception; | ||
} | ||
sinon.expectation = (function () { | ||
@@ -167,16 +163,2 @@ var slice = Array.prototype.slice; | ||
function timesInWords(times) { | ||
if (times == 0) { | ||
return "never"; | ||
} else if (times == 1) { | ||
return "once"; | ||
} else if (times == 2) { | ||
return "twice"; | ||
} else if (times == 3) { | ||
return "thrice"; | ||
} | ||
return times + " times"; | ||
} | ||
function callCountInWords(callCount) { | ||
@@ -186,3 +168,3 @@ if (callCount == 0) { | ||
} else { | ||
return "called " + timesInWords(callCount); | ||
return "called " + times(callCount); | ||
} | ||
@@ -196,6 +178,6 @@ } | ||
if (typeof min == "number" && typeof max == "number") { | ||
var str = timesInWords(min); | ||
var str = times(min); | ||
if (min != max) { | ||
str = "at least " + str + " and at most " + timesInWords(max); | ||
str = "at least " + str + " and at most " + times(max); | ||
} | ||
@@ -207,6 +189,6 @@ | ||
if (typeof min == "number") { | ||
return "at least " + timesInWords(min); | ||
return "at least " + times(min); | ||
} | ||
return "at most " + timesInWords(max); | ||
return "at most " + times(max); | ||
} | ||
@@ -307,7 +289,7 @@ | ||
this.failed = true; | ||
err(this.method + " already called " + timesInWords(this.maxCalls)); | ||
sinon.expectation.fail(this.method + " already called " + times(this.maxCalls)); | ||
} | ||
if ("expectedThis" in this && this.expectedThis !== thisValue) { | ||
err(this.method + " called with " + thisValue + " as thisValue, expected " + | ||
sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + | ||
this.expectedThis); | ||
@@ -321,3 +303,3 @@ } | ||
if (!args || args.length === 0) { | ||
err(this.method + " received no arguments, expected " + | ||
sinon.expectation.fail(this.method + " received no arguments, expected " + | ||
this.expectedArguments.join()); | ||
@@ -327,3 +309,3 @@ } | ||
if (args.length < this.expectedArguments.length) { | ||
err(this.method + " received too few arguments (" + args.join() + | ||
sinon.expectation.fail(this.method + " received too few arguments (" + args.join() + | ||
"), expected " + this.expectedArguments.join()); | ||
@@ -334,3 +316,3 @@ } | ||
args.length != this.expectedArguments.length) { | ||
err(this.method + " received too many arguments (" + args.join() + | ||
sinon.expectation.fail(this.method + " received too many arguments (" + args.join() + | ||
"), expected " + this.expectedArguments.join()); | ||
@@ -341,3 +323,3 @@ } | ||
if (!sinon.deepEqual(this.expectedArguments[i], args[i])) { | ||
err(this.method + " received wrong arguments (" + args.join() + | ||
sinon.expectation.fail(this.method + " received wrong arguments (" + args.join() + | ||
"), expected " + this.expectedArguments.join()); | ||
@@ -401,3 +383,3 @@ } | ||
if (!this.expectsExactArgCount) { | ||
args.push("[...]"); | ||
push.call(args, "[...]"); | ||
} | ||
@@ -422,6 +404,13 @@ | ||
if (!this.met()) { | ||
err(this.toString()); | ||
sinon.expectation.fail(this.toString()); | ||
} | ||
return true; | ||
}, | ||
fail: function (message) { | ||
var exception = new Error(message); | ||
exception.name = "ExpectationError"; | ||
throw exception; | ||
} | ||
@@ -428,0 +417,0 @@ }; |
@@ -21,3 +21,3 @@ /** | ||
if (typeof module == "object" && typeof require == "function") { | ||
var sinon = require("sinon"); | ||
var sinon = require("../sinon"); | ||
sinon.extend(sinon, require("./util/fake_timers")); | ||
@@ -27,2 +27,4 @@ } | ||
(function () { | ||
var push = [].push; | ||
function exposeValue(sandbox, config, key, value) { | ||
@@ -36,3 +38,3 @@ if (!value) { | ||
} else { | ||
sandbox.args.push(value); | ||
push.call(sandbox.args, value); | ||
} | ||
@@ -39,0 +41,0 @@ } |
@@ -18,5 +18,6 @@ /* @depend ../sinon.js */ | ||
var callId = 0; | ||
var push = [].push; | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -44,6 +45,6 @@ | ||
function delegateToCalls(api, method, matchAny, actual) { | ||
function delegateToCalls(api, method, matchAny, actual, notCalled) { | ||
api[method] = function () { | ||
if (!this.called) { | ||
return false; | ||
return !!notCalled; | ||
} | ||
@@ -136,5 +137,5 @@ | ||
this.calledThrice = this.callCount == 3; | ||
this.thisValues.push(thisValue); | ||
this.args.push(args); | ||
this.callIds.push(callId++); | ||
push.call(this.thisValues, thisValue); | ||
push.call(this.args, args); | ||
push.call(this.callIds, callId++); | ||
@@ -148,10 +149,10 @@ try { | ||
} catch (e) { | ||
this.returnValues.push(undefined); | ||
push.call(this.returnValues, undefined); | ||
exception = e; | ||
throw e; | ||
} finally { | ||
this.exceptions.push(exception); | ||
push.call(this.exceptions, exception); | ||
} | ||
this.returnValues.push(returnValue); | ||
push.call(this.returnValues, returnValue); | ||
@@ -207,3 +208,3 @@ return returnValue; | ||
fake.matchingAguments = args; | ||
this.fakes.push(fake); | ||
push.call(this.fakes, fake); | ||
@@ -224,2 +225,20 @@ fake.withArgs = function () { | ||
} | ||
}, | ||
printf: function (format) { | ||
var spy = this; | ||
var args = [].slice.call(arguments, 1); | ||
var formatter; | ||
return (format || "").replace(/%(.)/g, function (match, specifyer) { | ||
formatter = spyApi.formatters[specifyer]; | ||
if (typeof formatter == "function") { | ||
return formatter.call(null, spy, args); | ||
} else if (!isNaN(parseInt(specifyer), 10)) { | ||
return sinon.format(args[specifyer - 1]); | ||
} | ||
return "%" + specifyer; | ||
}); | ||
} | ||
@@ -234,2 +253,3 @@ }; | ||
delegateToCalls(spyApi, "alwaysCalledWithExactly", false, "calledWithExactly"); | ||
delegateToCalls(spyApi, "neverCalledWith", false, "notCalledWith", true); | ||
delegateToCalls(spyApi, "threw", true); | ||
@@ -239,3 +259,39 @@ delegateToCalls(spyApi, "alwaysThrew", false, "threw"); | ||
delegateToCalls(spyApi, "alwaysReturned", false, "returned"); | ||
delegateToCalls(spyApi, "calledWithNew", true); | ||
delegateToCalls(spyApi, "alwaysCalledWithNew", false, "calledWithNew"); | ||
spyApi.formatters = { | ||
"c": function (spy) { | ||
return sinon.timesInWords(spy.callCount); | ||
}, | ||
"n": function (spy) { | ||
return spy.toString(); | ||
}, | ||
"C": function (spy) { | ||
var calls = []; | ||
for (var i = 0, l = spy.callCount; i < l; ++i) { | ||
push.call(calls, " " + spy.getCall(i).toString()); | ||
} | ||
return calls.length > 0 ? "\n" + calls.join("\n") : ""; | ||
}, | ||
"t": function (spy) { | ||
var objects = []; | ||
for (var i = 0, l = spy.callCount; i < l; ++i) { | ||
push.call(objects, sinon.format(spy.thisValues[i])); | ||
} | ||
return objects.join(", "); | ||
}, | ||
"*": function (spy, args) { | ||
return args.join(", "); | ||
} | ||
}; | ||
return spyApi; | ||
@@ -278,2 +334,11 @@ }())); | ||
notCalledWith: function notCalledWith() { | ||
for (var i = 0, l = arguments.length; i < l; i += 1) { | ||
if (!sinon.deepEqual(arguments[i], this.args[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
returned: function returned(value) { | ||
@@ -295,2 +360,6 @@ return this.returnValue === value; | ||
calledWithNew: function calledWithNew(thisValue) { | ||
return this.thisValue instanceof this.proxy; | ||
}, | ||
calledBefore: function (other) { | ||
@@ -309,3 +378,3 @@ return this.callId < other.callId; | ||
for (var i = 0, l = this.args.length; i < l; ++i) { | ||
args.push(sinon.format(this.args[i])); | ||
push.call(args, sinon.format(this.args[i])); | ||
} | ||
@@ -332,2 +401,7 @@ | ||
spy.spyCall = spyCall; | ||
// This steps outside the module sandbox and will be removed | ||
sinon.spyCall = spyCall; | ||
if (commonJSModule) { | ||
@@ -338,4 +412,2 @@ module.exports = spy; | ||
} | ||
sinon.spyCall = spyCall; | ||
}(typeof sinon == "object" && sinon || null)); |
@@ -21,3 +21,3 @@ /** | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -21,3 +21,3 @@ /** | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -24,0 +24,0 @@ |
@@ -23,3 +23,3 @@ /** | ||
if (!sinon && commonJSModule) { | ||
sinon = require("sinon"); | ||
sinon = require("../sinon"); | ||
} | ||
@@ -26,0 +26,0 @@ |
@@ -24,2 +24,3 @@ /** | ||
sinon.fakeServer = (function () { | ||
var push = [].push; | ||
function F() {} | ||
@@ -94,3 +95,3 @@ | ||
var server = this; | ||
this.requests.push(xhrObj); | ||
push.call(this.requests, xhrObj); | ||
@@ -113,3 +114,3 @@ xhrObj.onSend = function () { | ||
if (this.fakeHTTPMethods && /post/i.test(request.method)) { | ||
var matches = request.requestBody.match(/_method=([^\b;]+)/); | ||
var matches = (request.requestBody || "").match(/_method=([^\b;]+)/); | ||
return !!matches ? matches[1] : request.method; | ||
@@ -127,3 +128,3 @@ } | ||
this.queue.push(xhr); | ||
push.call(this.queue, xhr); | ||
} else { | ||
@@ -148,3 +149,3 @@ this.processRequest(xhr); | ||
this.responses.push({ | ||
push.call(this.responses, { | ||
method: method, | ||
@@ -151,0 +152,0 @@ url: url, |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @depend event.js | ||
*/ | ||
/*jslint eqeqeq: false, onevar: false*/ | ||
@@ -65,3 +68,3 @@ /*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/ | ||
sinon.extend(FakeXMLHttpRequest.prototype, { | ||
sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, { | ||
async: true, | ||
@@ -88,2 +91,4 @@ | ||
} | ||
this.dispatchEvent(new sinon.Event("readystatechange")); | ||
}, | ||
@@ -150,3 +155,3 @@ | ||
if (this.readyState > sinon.FakeXMLHttpRequest.OPENED) { | ||
if (this.readyState > sinon.FakeXMLHttpRequest.UNSENT && this.sendFlag) { | ||
this.readyStateChange(sinon.FakeXMLHttpRequest.DONE); | ||
@@ -342,3 +347,3 @@ this.sendFlag = false; | ||
global.ActiveXObject = function ActiveXObject(objId) { | ||
if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/.test(objId)) { | ||
if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) { | ||
return new sinon.FakeXMLHttpRequest(); | ||
@@ -345,0 +350,0 @@ } |
@@ -1,16 +0,16 @@ | ||
{ | ||
{ | ||
"name": "sinon", | ||
"description": "JavaScript test spies, stubs and mocks.", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"homepage": "http://cjohansen.no/sinon/", | ||
"author": "Christian Johansen", | ||
"repository": { | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/cjohansen/Sinon.JS.git" | ||
}, | ||
"bugs": { | ||
"bugs": { | ||
"mail": "christian@cjohansen.no", | ||
"web": "http://github.com/cjohansen/Sinon.JS/issues" | ||
}, | ||
"licenses": [ | ||
"licenses": [ | ||
{ "type": "BSD", | ||
@@ -17,0 +17,0 @@ "url": "http://github.com/cjohansen/Sinon.JS/blob/master/LICENSE" |
var jstestdriver = {}; | ||
load("test/rhino/env.rhino.1.2.js"); | ||
load("test/rhino/Asserts.js"); | ||
var assert = assertTrue; | ||
load("test/rhino/test_case_shim.js"); | ||
load("test/Asserts.js"); | ||
load("test/test_case_shim.js"); | ||
@@ -8,0 +7,0 @@ load("lib/sinon.js"); |
@@ -23,2 +23,7 @@ /*jslint onevar: false, eqeqeq: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("./test_case_shim"); | ||
var sinon = require("../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -131,2 +136,25 @@ testCase("SinonTest", { | ||
testCase("WrappedPrototypeMethodTest", { | ||
setUp: function () { | ||
this.type = function () {}; | ||
this.type.prototype.method = function () {}; | ||
this.object = new this.type(); | ||
}, | ||
"wrap should add owned property": function () { | ||
var wrapper = sinon.wrapMethod(this.object, "method", function () {}); | ||
assertSame(wrapper, this.object.method); | ||
assert(this.object.hasOwnProperty("method")); | ||
}, | ||
"restore should remove owned property": function () { | ||
sinon.wrapMethod(this.object, "method", function () {}); | ||
this.object.method.restore(); | ||
assertSame(this.type.prototype.method, this.object.method); | ||
assertFalse(this.object.hasOwnProperty("method")); | ||
} | ||
}); | ||
testCase("SinonDeepEqualTest", { | ||
@@ -171,2 +199,3 @@ "should pass primitives": function () { | ||
/*:DOC element = <div class="hey"></div> */ | ||
if (typeof document == "undefined") return console.log("Test requires DOM"); | ||
@@ -178,2 +207,3 @@ assert(sinon.deepEqual(this.element, this.element)); | ||
/*:DOC element = <div class="hey"></div> */ | ||
if (typeof document == "undefined") return console.log("Test requires DOM"); | ||
var el = document.createElement("div"); | ||
@@ -186,2 +216,3 @@ | ||
/*:DOC += <div id="hey"></div> */ | ||
if (typeof document == "undefined") return console.log("Test requires DOM"); | ||
var el = document.getElementById("hey"); | ||
@@ -229,20 +260,2 @@ sinon.deepEqual(el, {}) | ||
testCase("SinonKeysTest", { | ||
"should be method": function () { | ||
assertFunction(sinon.keys); | ||
}, | ||
"should return enumerable keys": function () { | ||
var obj = { a: 0, b: "", c: null, d: function () {}, e: {}, f: false }; | ||
assertEquals(["a", "b", "c", "d", "e", "f"], sinon.keys(obj)); | ||
}, | ||
"should return sorted keys": function () { | ||
var obj = { d: function () {}, e: {}, f: false, a: 0, b: "", c: null }; | ||
assertEquals(["a", "b", "c", "d", "e", "f"], sinon.keys(obj)); | ||
} | ||
}); | ||
testCase("ExtendTest", { | ||
@@ -249,0 +262,0 @@ "should copy all properties": function () { |
@@ -28,2 +28,7 @@ /*jslint onevar: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function (global) { | ||
@@ -546,2 +551,41 @@ testCase("SinonAssertTest", { | ||
testCase("SinonAssertNeverCalledWithTest", { | ||
setUp: stubSetUp, | ||
tearDown: stubTearDown, | ||
"should fail when method fails": function () { | ||
var object = {}; | ||
sinon.stub(this.stub, "neverCalledWith").returns(false); | ||
var stub = this.stub; | ||
assertException(function () { | ||
sinon.assert.neverCalledWith(stub, object, 1); | ||
}); | ||
assert(this.stub.neverCalledWith.calledWith(object, 1)); | ||
assert(sinon.assert.fail.called); | ||
}, | ||
"should not fail when method doesn't fail": function () { | ||
var object = {}; | ||
sinon.stub(this.stub, "neverCalledWith").returns(true); | ||
var stub = this.stub; | ||
assertNoException(function () { | ||
sinon.assert.neverCalledWith(stub, object, 1); | ||
}); | ||
assert(this.stub.neverCalledWith.calledWith(object, 1)); | ||
assertFalse(sinon.assert.fail.called); | ||
}, | ||
"should call pass callback": function () { | ||
this.stub("yeah"); | ||
sinon.assert.neverCalledWith(this.stub, "nah!"); | ||
assert(sinon.assert.pass.calledOnce); | ||
assert(sinon.assert.pass.calledWith("neverCalledWith")); | ||
} | ||
}); | ||
testCase("SinonAssertThrewTest", { | ||
@@ -994,2 +1038,11 @@ setUp: stubSetUp, | ||
"assert.neverCalledWith exception message": function () { | ||
this.obj.doSomething(1, 2, 3); | ||
assertEquals("expected doSomething to never be called with " + | ||
"arguments 1, 2\n doSomething(1, 2, 3)", | ||
this.message("neverCalledWith", | ||
this.obj.doSomething, 1, 2)); | ||
}, | ||
"assert.threw exception message": function () { | ||
@@ -1013,2 +1066,2 @@ this.obj.doSomething(1, 3, "hey"); | ||
}); | ||
}(this)); | ||
}(typeof global == "object" ? global : this)); |
@@ -22,2 +22,7 @@ /*jslint onevar: false, eqeqeq: false, plusplus: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -214,5 +219,2 @@ testCase("CollectionCreateTest", { | ||
this.collection = sinon.create(sinon.collection); | ||
}, | ||
"should call restore on all fakes": function () { | ||
this.collection.fakes = [{ | ||
@@ -223,7 +225,17 @@ restore: sinon.spy.create() | ||
}]; | ||
}, | ||
"should call restore on all fakes": function () { | ||
var fake0 = this.collection.fakes[0]; | ||
var fake1 = this.collection.fakes[1]; | ||
this.collection.restore(); | ||
assert(this.collection.fakes[0].restore.called); | ||
assert(this.collection.fakes[1].restore.called); | ||
assert(fake0.restore.called); | ||
assert(fake1.restore.called); | ||
}, | ||
"should remove from collection when restored": function () { | ||
this.collection.restore(); | ||
assert(this.collection.fakes.length == 0); | ||
} | ||
@@ -230,0 +242,0 @@ }); |
@@ -22,2 +22,7 @@ /*jslint onevar: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -24,0 +29,0 @@ testCase("MockCreateTest", { |
@@ -26,3 +26,10 @@ /*jslint onevar: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function (global) { | ||
var supportsAjax = typeof XMLHttpRequest != "undefined" || typeof ActiveXObject != "undefined"; | ||
testCase("SandboxTest", { | ||
@@ -94,70 +101,72 @@ "should be object": function () { | ||
testCase("SandboxUseFakeXMLHttpRequestTest", { | ||
setUp: function () { | ||
this.sandbox = sinon.create(sinon.sandbox); | ||
}, | ||
if (globalXHR || globalAXO) { | ||
testCase("SandboxUseFakeXMLHttpRequestTest", { | ||
setUp: function () { | ||
this.sandbox = sinon.create(sinon.sandbox); | ||
}, | ||
tearDown: function () { | ||
this.sandbox.restore(); | ||
}, | ||
tearDown: function () { | ||
this.sandbox.restore(); | ||
}, | ||
"should call sinon.useFakeXMLHttpRequest": sinon.test(function () { | ||
this.stub(sinon, "useFakeXMLHttpRequest").returns({ restore: function () {} }); | ||
this.sandbox.useFakeXMLHttpRequest(); | ||
"should call sinon.useFakeXMLHttpRequest": sinon.test(function () { | ||
this.stub(sinon, "useFakeXMLHttpRequest").returns({ restore: function () {} }); | ||
this.sandbox.useFakeXMLHttpRequest(); | ||
assert(sinon.useFakeXMLHttpRequest.called); | ||
}), | ||
assert(sinon.useFakeXMLHttpRequest.called); | ||
}), | ||
"should add fake xhr to fake collection": function () { | ||
this.sandbox.useFakeXMLHttpRequest(); | ||
this.sandbox.restore(); | ||
"should add fake xhr to fake collection": function () { | ||
this.sandbox.useFakeXMLHttpRequest(); | ||
this.sandbox.restore(); | ||
assertSame(globalXHR, global.XMLHttpRequest); | ||
assertSame(globalAXO, global.ActiveXObject); | ||
} | ||
}); | ||
assertSame(globalXHR, global.XMLHttpRequest); | ||
assertSame(globalAXO, global.ActiveXObject); | ||
} | ||
}); | ||
testCase("SandboxUseServer", { | ||
setUp: function () { | ||
this.sandbox = sinon.create(sinon.sandbox); | ||
}, | ||
testCase("SandboxUseServer", { | ||
setUp: function () { | ||
this.sandbox = sinon.create(sinon.sandbox); | ||
}, | ||
tearDown: function () { | ||
this.sandbox.restore(); | ||
}, | ||
tearDown: function () { | ||
this.sandbox.restore(); | ||
}, | ||
"should return server": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
"should return server": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
assertObject(server); | ||
assertFunction(server.restore); | ||
}, | ||
assertObject(server); | ||
assertFunction(server.restore); | ||
}, | ||
"should expose server property": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
"should expose server property": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
assertSame(server, this.sandbox.server); | ||
}, | ||
assertSame(server, this.sandbox.server); | ||
}, | ||
"should create server": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
"should create server": function () { | ||
var server = this.sandbox.useFakeServer(); | ||
assert(sinon.fakeServer.isPrototypeOf(server)); | ||
}, | ||
assert(sinon.fakeServer.isPrototypeOf(server)); | ||
}, | ||
"should create server with cock": function () { | ||
this.sandbox.serverPrototype = sinon.fakeServerWithClock; | ||
var server = this.sandbox.useFakeServer(); | ||
"should create server with cock": function () { | ||
this.sandbox.serverPrototype = sinon.fakeServerWithClock; | ||
var server = this.sandbox.useFakeServer(); | ||
assert(sinon.fakeServerWithClock.isPrototypeOf(server)); | ||
}, | ||
assert(sinon.fakeServerWithClock.isPrototypeOf(server)); | ||
}, | ||
"should add server to fake collection": function () { | ||
this.sandbox.useFakeServer(); | ||
this.sandbox.restore(); | ||
"should add server to fake collection": function () { | ||
this.sandbox.useFakeServer(); | ||
this.sandbox.restore(); | ||
assertSame(globalXHR, global.XMLHttpRequest); | ||
assertSame(globalAXO, global.ActiveXObject); | ||
} | ||
}); | ||
assertSame(globalXHR, global.XMLHttpRequest); | ||
assertSame(globalAXO, global.ActiveXObject); | ||
} | ||
}); | ||
} | ||
@@ -203,2 +212,7 @@ testCase("SandboxInjectTest", { | ||
"should define server and requests when using fake time": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
this.sandbox.useFakeServer(); | ||
@@ -216,2 +230,7 @@ this.sandbox.inject(this.obj); | ||
"should define all possible fakes": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
this.sandbox.useFakeServer(); | ||
@@ -289,9 +308,16 @@ this.sandbox.useFakeTimers(); | ||
this.clock = {}; | ||
sinon.stub(sinon.fakeServer, "create").returns(this.fakeServer); | ||
sinon.stub(sinon, "useFakeTimers").returns(this.clock); | ||
if (sinon.fakeServer) { | ||
sinon.stub(sinon.fakeServer, "create").returns(this.fakeServer); | ||
} | ||
}, | ||
tearDown: function () { | ||
sinon.fakeServer.create.restore(); | ||
sinon.useFakeTimers.restore(); | ||
if (sinon.fakeServer) { | ||
sinon.fakeServer.create.restore(); | ||
} | ||
}, | ||
@@ -334,2 +360,7 @@ | ||
"should yield server when faking xhr": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var sandbox = sinon.sandbox.create(sinon.getConfig({ | ||
@@ -347,2 +378,7 @@ injectIntoThis: false, | ||
"should use serverWithClock when faking xhr": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var sandbox = sinon.sandbox.create(sinon.getConfig({ | ||
@@ -358,2 +394,7 @@ injectIntoThis: false, | ||
"should yield clock when faking timers": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var sandbox = sinon.sandbox.create(sinon.getConfig({ | ||
@@ -379,2 +420,7 @@ injectIntoThis: false, | ||
"should inject properties into object": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var object = {}; | ||
@@ -397,2 +443,7 @@ | ||
"should inject server and clock when only enabling them": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var object = {}; | ||
@@ -429,2 +480,2 @@ | ||
}); | ||
}(this)); | ||
}(typeof global == "object" ? global : this)); |
@@ -25,2 +25,7 @@ /*jslint onevar: false, eqeqeq: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -382,2 +387,80 @@ testCase("SpyCreateTest", { | ||
testCase("SpyCalledWithNewTest", { | ||
setUp: function () { | ||
this.spy = sinon.spy.create(); | ||
}, | ||
"should be false if spy wasn't called": function () { | ||
assertFalse(this.spy.calledWithNew()); | ||
}, | ||
"should be true if called with new": function () { | ||
var result = new this.spy(); | ||
assert(this.spy.calledWithNew()); | ||
}, | ||
"should be true if called with new on custom constructor": function () { | ||
function MyThing() {} | ||
MyThing.prototype = {}; | ||
var ns = { MyThing: MyThing }; | ||
sinon.spy(ns, "MyThing"); | ||
var result = new ns.MyThing(); | ||
assert(ns.MyThing.calledWithNew()); | ||
}, | ||
"should be false if called as function": function () { | ||
this.spy(); | ||
assertFalse(this.spy.calledWithNew()); | ||
}, | ||
"should be true if called with new at least once": function () { | ||
var object = {}; | ||
this.spy(); | ||
var a = new this.spy(); | ||
this.spy(object); | ||
this.spy(window); | ||
assert(this.spy.calledWithNew()); | ||
}, | ||
"should be true newed constructor returns object": function () { | ||
function MyThing() { return {}; } | ||
var object = { MyThing: MyThing }; | ||
sinon.spy(object, "MyThing"); | ||
var result = new object.MyThing; | ||
assert(object.MyThing.calledWithNew()); | ||
} | ||
}); | ||
testCase("SpyAlwaysCalledWithNewTest", { | ||
setUp: function () { | ||
this.spy = sinon.spy.create(); | ||
}, | ||
"should be false if spy wasn't called": function () { | ||
assertFalse(this.spy.alwaysCalledWithNew()); | ||
}, | ||
"should be true if always called with new": function () { | ||
var result = new this.spy(); | ||
var result2 = new this.spy(); | ||
var result3 = new this.spy(); | ||
assert(this.spy.alwaysCalledWithNew()); | ||
}, | ||
"should be false if called as function once": function () { | ||
var result = new this.spy(); | ||
var result2 = new this.spy(); | ||
this.spy(); | ||
assertFalse(this.spy.alwaysCalledWithNew()); | ||
} | ||
}); | ||
testCase("SpyThisValueTest", { | ||
@@ -507,2 +590,48 @@ setUp: function () { | ||
testCase("SpyNeverCalledWithTest", { | ||
setUp: function () { | ||
this.spy = sinon.spy.create(); | ||
}, | ||
"should return true if spy was not called": function () { | ||
assert(this.spy.neverCalledWith(1, 2, 3)); | ||
}, | ||
"should return false if spy was called with args": function () { | ||
this.spy(1, 2, 3); | ||
assertFalse(this.spy.neverCalledWith(1, 2, 3)); | ||
}, | ||
"should return false if called with args at least once": function () { | ||
this.spy(1, 3, 3); | ||
this.spy(1, 2, 3); | ||
this.spy(3, 2, 3); | ||
assertFalse(this.spy.neverCalledWith(1, 2, 3)); | ||
}, | ||
"should return true if not called with args": function () { | ||
this.spy(1, 3, 3); | ||
this.spy(2); | ||
this.spy(); | ||
assert(this.spy.neverCalledWith(1, 2, 3)); | ||
}, | ||
"should return false for partial match": function () { | ||
this.spy(1, 3, 3); | ||
this.spy(2); | ||
this.spy(); | ||
assertFalse(this.spy.neverCalledWith(1, 3)); | ||
}, | ||
"should match all arguments individually, not as array": function () { | ||
this.spy([1, 2, 3]); | ||
assert(this.spy.neverCalledWith(1, 2, 3)); | ||
} | ||
}); | ||
testCase("SpyArgsTest", { | ||
@@ -1088,3 +1217,3 @@ setUp: function () { | ||
this.returnValue = function () {}; | ||
this.call = sinon.spyCall.create(function () {}, this.thisValue, this.args, this.returnValue); | ||
this.call = sinon.spy.spyCall.create(function () {}, this.thisValue, this.args, this.returnValue); | ||
} | ||
@@ -1175,2 +1304,40 @@ | ||
testCase("SpyCallNotCalledWithTest", { | ||
setUp: spyCallSetUp, | ||
"should return false if all args match": function () { | ||
var args = this.args; | ||
assertFalse(this.call.notCalledWith(args[0], args[1], args[2])); | ||
}, | ||
"should return false if first args match": function () { | ||
var args = this.args; | ||
assertFalse(this.call.notCalledWith(args[0], args[1])); | ||
}, | ||
"should return false if first arg match": function () { | ||
var args = this.args; | ||
assertFalse(this.call.notCalledWith(args[0])); | ||
}, | ||
"should return false for no args": function () { | ||
assertFalse(this.call.notCalledWith()); | ||
}, | ||
"should return true for too many args": function () { | ||
var args = this.args; | ||
assert(this.call.notCalledWith(args[0], args[1], args[2], {})); | ||
}, | ||
"should return true for wrong arg": function () { | ||
var args = this.args; | ||
assert(this.call.notCalledWith(args[0], args[2])); | ||
} | ||
}); | ||
testCase("SpyCallCalledWithExactlyTest", { | ||
@@ -1204,3 +1371,3 @@ setUp: spyCallSetUp, | ||
"should return true for no arguments": function () { | ||
var call = sinon.spyCall.create(function () {}, {}, []); | ||
var call = sinon.spy.spyCall.create(function () {}, {}, []); | ||
@@ -1211,3 +1378,3 @@ assert(call.calledWithExactly()); | ||
"should return false when called with no args but matching one": function () { | ||
var call = sinon.spyCall.create(function () {}, {}, []); | ||
var call = sinon.spy.spyCall.create(function () {}, {}, []); | ||
@@ -1214,0 +1381,0 @@ assertFalse(call.calledWithExactly({})); |
@@ -22,2 +22,7 @@ /*jslint onevar: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -24,0 +29,0 @@ testCase("StubCreateTest", { |
@@ -20,2 +20,7 @@ /*jslint onevar: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
@@ -22,0 +27,0 @@ testCase("SinonTestCaseTest", { |
@@ -24,3 +24,10 @@ /*jslint onevar: false, eqeqeq: false, browser: true*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../test_case_shim"); | ||
var sinon = require("../../lib/sinon"); | ||
} | ||
(function () { | ||
var supportsAjax = typeof XMLHttpRequest != "undefined" || typeof ActiveXObject != "undefined"; | ||
testCase("SinonTestTest", { | ||
@@ -291,2 +298,7 @@ tearDown: function () { | ||
"should yield server when faking xhr": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var stubbed, mocked, server; | ||
@@ -314,2 +326,7 @@ var obj = { meth: function () {} }; | ||
"should use serverWithClock when faking xhr": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var server; | ||
@@ -332,17 +349,14 @@ | ||
"should yield clock when faking timers": function () { | ||
var server, clock; | ||
var clock; | ||
sinon.config = { | ||
injectIntoThis: false, | ||
properties: ["server", "clock"] | ||
properties: ["clock"] | ||
}; | ||
sinon.test(function (s, c) { | ||
server = s; | ||
sinon.test(function (c) { | ||
clock = c; | ||
assertEquals(2, arguments.length); | ||
assertEquals(1, arguments.length); | ||
})(); | ||
assertFakeServer(server); | ||
assertClock(clock); | ||
@@ -382,3 +396,3 @@ }, | ||
sinon.config = { | ||
properties: ["server", "clock"] | ||
properties: ["clock"] | ||
}; | ||
@@ -390,3 +404,2 @@ | ||
assertEquals(0, testCase.args.length); | ||
assertFakeServer(testCase.server); | ||
assertClock(testCase.clock); | ||
@@ -396,6 +409,10 @@ assertUndefined(testCase.spy); | ||
assertUndefined(testCase.mock); | ||
assertUndefined(testCase.requests); | ||
}, | ||
"should inject properties into object": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var testCase = boundTestCase(); | ||
@@ -437,4 +454,2 @@ var obj = {}; | ||
assertFunction(testCase.mock); | ||
assertObject(testCase.requests); | ||
assertObject(testCase.server); | ||
assertObject(testCase.clock); | ||
@@ -444,2 +459,7 @@ }, | ||
"should inject server and clock when only enabling them": function () { | ||
if (!supportsAjax) { | ||
jstestdriver.console.log("Ajax unavailable, aborting"); | ||
return; | ||
} | ||
var testCase = boundTestCase(); | ||
@@ -446,0 +466,0 @@ var obj = {}; |
@@ -583,2 +583,10 @@ /*jslint onevar: false, browser: false, regexp: false, browser: true*/ | ||
assertEquals([200, {}, "OK"], this.request.respond.args[0]); | ||
}, | ||
"should not fail when getting the HTTP method from a request with no body": | ||
function () { | ||
var server = this.server; | ||
server.fakeHTTPMethods = true; | ||
assertEquals("POST", server.getHTTPMethod({ method: "POST" })); | ||
} | ||
@@ -585,0 +593,0 @@ }); |
@@ -29,2 +29,8 @@ /*jslint onevar: false, eqeqeq: false, plusplus: false*/ | ||
if (typeof require == "function" && typeof testCase == "undefined") { | ||
var testCase = require("../../test_case_shim"); | ||
var sinon = require("../../../lib/sinon"); | ||
sinon.extend(sinon, require("../../../lib/sinon/util/fake_timers")); | ||
} | ||
(function (global) { | ||
@@ -488,6 +494,9 @@ testCase("SetTimeOutTest", { | ||
"should create real Date objects when Date constructor is gone": function () { | ||
var realDate = new Date(); | ||
Date = function () {}; | ||
global.Date = function () {}; | ||
var date = new this.clock.Date(); | ||
assert(this.Date.prototype.isPrototypeOf(date)); | ||
assertSame(realDate.constructor.prototype, date.constructor.prototype); | ||
}, | ||
@@ -655,2 +664,3 @@ | ||
this.clock.restore(); | ||
clearTimeout(this.timer); | ||
}, | ||
@@ -715,3 +725,3 @@ | ||
setTimeout(stub, 1000); | ||
this.timer = setTimeout(stub, 1000); | ||
this.clock.tick(1000); | ||
@@ -756,3 +766,3 @@ | ||
setInterval(stub, 1000); | ||
this.timer = setInterval(stub, 1000); | ||
this.clock.tick(1000); | ||
@@ -817,2 +827,2 @@ | ||
}); | ||
}(this)); | ||
}(typeof global != "undefined" ? global : this)); |
@@ -357,2 +357,13 @@ /*jslint onevar: false, eqeqeq: false, browser: true*/ | ||
"should dispatch event using DOM Event interface": function () { | ||
var listener = sinon.spy(); | ||
this.xhr.open("POST", "/", false); | ||
this.xhr.addEventListener("readystatechange", listener); | ||
this.xhr.send("Data"); | ||
assert(listener.calledOnce); | ||
assertEquals("readystatechange", listener.args[0][0].type); | ||
}, | ||
"should dispatch onSend callback if set": function () { | ||
@@ -747,7 +758,6 @@ this.xhr.open("POST", "/", true); | ||
"should set state to DONE if headers received": function () { | ||
"should set state to DONE if sent before": function () { | ||
var readyState; | ||
this.xhr.open("GET", "/"); | ||
this.xhr.send(); | ||
this.xhr.setResponseHeaders({ "X-Test": "Sumptn" }); | ||
@@ -763,6 +773,5 @@ this.xhr.onreadystatechange = function () { | ||
"should set send flag to false if headers received": function () { | ||
"should set send flag to false if sent before": function () { | ||
this.xhr.open("GET", "/"); | ||
this.xhr.send(); | ||
this.xhr.setResponseHeaders({ "X-Test": "Sumptn" }); | ||
@@ -774,6 +783,5 @@ this.xhr.abort(); | ||
"should dispatch readystatechange event if headers received": function () { | ||
"should dispatch readystatechange event if sent before": function () { | ||
this.xhr.open("GET", "/"); | ||
this.xhr.send(); | ||
this.xhr.setResponseHeaders({ "X-Test": "Sumptn" }); | ||
this.xhr.onreadystatechange = sinon.stub(); | ||
@@ -786,6 +794,5 @@ | ||
"should set readyState to unsent if headers received": function () { | ||
"should set readyState to unsent if sent before": function () { | ||
this.xhr.open("GET", "/"); | ||
this.xhr.send(); | ||
this.xhr.setResponseHeaders({ "X-Test": "Sumptn" }); | ||
@@ -805,3 +812,4 @@ this.xhr.abort(); | ||
"should not dispatch readystatechange event if readyState is opened": function () { | ||
"should not dispatch readystatechange event if readyState is opened but not sent": function () { | ||
this.xhr.open("GET", "/"); | ||
this.xhr.onreadystatechange = sinon.stub(); | ||
@@ -808,0 +816,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
0
1091216
48
23533