mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-11 05:46:37 +01:00
Add sinon.js
This commit is contained in:
parent
236afa4003
commit
25906c1635
@ -15,6 +15,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="vendor/chai-1.3.0.js"></script>
|
<script type="text/javascript" src="vendor/chai-1.3.0.js"></script>
|
||||||
|
<script type="text/javascript" src="vendor/sinon-1.5.0.js"></script>
|
||||||
|
<script type="text/javascript" src="vendor/sinon-chai-2.1.2.js"></script>
|
||||||
<script>
|
<script>
|
||||||
should = chai.should();
|
should = chai.should();
|
||||||
</script>
|
</script>
|
||||||
|
4142
spec/vendor/sinon-1.5.0.js
vendored
Normal file
4142
spec/vendor/sinon-1.5.0.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
95
spec/vendor/sinon-chai-2.1.2.js
vendored
Normal file
95
spec/vendor/sinon-chai-2.1.2.js
vendored
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
(function (sinonChai) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// Module systems magic dance.
|
||||||
|
|
||||||
|
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
|
||||||
|
// NodeJS
|
||||||
|
module.exports = sinonChai;
|
||||||
|
} else if (typeof define === "function" && define.amd) {
|
||||||
|
// AMD
|
||||||
|
define(function () {
|
||||||
|
return sinonChai;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Other environment (usually <script> tag): plug in to global chai instance directly.
|
||||||
|
chai.use(sinonChai);
|
||||||
|
}
|
||||||
|
}(function sinonChai(chai, utils) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var slice = Array.prototype.slice;
|
||||||
|
|
||||||
|
function isSpy(putativeSpy) {
|
||||||
|
return typeof putativeSpy === "function" &&
|
||||||
|
typeof putativeSpy.getCall === "function" &&
|
||||||
|
typeof putativeSpy.calledWithExactly === "function";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCall(putativeCall) {
|
||||||
|
return putativeCall && isSpy(putativeCall.proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertCanWorkWith(assertion) {
|
||||||
|
if (!isSpy(assertion._obj) && !isCall(assertion._obj)) {
|
||||||
|
throw new TypeError(utils.inspect(assertion._obj) + " is not a spy or a call to a spy!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessages(spy, action, nonNegatedSuffix, always, args) {
|
||||||
|
var verbPhrase = always ? "always have " : "have ";
|
||||||
|
nonNegatedSuffix = nonNegatedSuffix || "";
|
||||||
|
spy = spy.proxy || spy;
|
||||||
|
|
||||||
|
function printfArray(array) {
|
||||||
|
return spy.printf.apply(spy, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
affirmative: printfArray(["expected %n to " + verbPhrase + action + nonNegatedSuffix].concat(args)),
|
||||||
|
negative: printfArray(["expected %n to not " + verbPhrase + action].concat(args))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function sinonProperty(name, action, nonNegatedSuffix) {
|
||||||
|
utils.addProperty(chai.Assertion.prototype, name, function () {
|
||||||
|
assertCanWorkWith(this);
|
||||||
|
|
||||||
|
var messages = getMessages(this._obj, action, nonNegatedSuffix, false);
|
||||||
|
this.assert(this._obj[name], messages.affirmative, messages.negative);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function exceptionalSinonMethod(chaiName, sinonName, action, nonNegatedSuffix) {
|
||||||
|
utils.addMethod(chai.Assertion.prototype, chaiName, function () {
|
||||||
|
assertCanWorkWith(this);
|
||||||
|
|
||||||
|
var alwaysSinonMethod = "always" + sinonName[0].toUpperCase() + sinonName.substring(1);
|
||||||
|
var shouldBeAlways = utils.flag(this, "always") && typeof this._obj[alwaysSinonMethod] === "function";
|
||||||
|
var sinonMethod = shouldBeAlways ? alwaysSinonMethod : sinonName;
|
||||||
|
|
||||||
|
var messages = getMessages(this._obj, action, nonNegatedSuffix, shouldBeAlways, slice.call(arguments));
|
||||||
|
this.assert(this._obj[sinonMethod].apply(this._obj, arguments), messages.affirmative, messages.negative);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function sinonMethod(name, action, nonNegatedSuffix) {
|
||||||
|
exceptionalSinonMethod(name, name, action, nonNegatedSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.addProperty(chai.Assertion.prototype, "always", function () {
|
||||||
|
utils.flag(this, "always", true);
|
||||||
|
});
|
||||||
|
|
||||||
|
sinonProperty("called", "been called", " at least once, but it was never called");
|
||||||
|
sinonProperty("calledOnce", "been called exactly once", ", but it was called %c%C");
|
||||||
|
sinonProperty("calledTwice", "been called exactly twice", ", but it was called %c%C");
|
||||||
|
sinonProperty("calledThrice", "been called exactly thrice", ", but it was called %c%C");
|
||||||
|
sinonMethod("calledBefore", "been called before %1");
|
||||||
|
sinonMethod("calledAfter", "been called after %1");
|
||||||
|
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
|
||||||
|
sinonMethod("calledWith", "been called with arguments %*", "%C");
|
||||||
|
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%C");
|
||||||
|
sinonMethod("returned", "returned %1");
|
||||||
|
exceptionalSinonMethod("thrown", "threw", "thrown %1");
|
||||||
|
}));
|
Loading…
Reference in New Issue
Block a user