Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: @cypress/sinon-chai @ 1.0.0 .. 1.1.0

lib/sinon-chai.js

@@ -1,6 +1,7 @@
-(function (sinonChai) {
- "use strict";
+"use strict";
+/* eslint-disable no-invalid-this */
+(function (sinonChai) {
// Module systems magic dance.
/* istanbul ignore else */
@@ -14,13 +15,15 @@
});
} else {
// Other environment (usually <script> tag): plug in to global chai instance directly.
+ /* global chai: false */
chai.use(sinonChai);
}
-}(function sinonChai(chai, utils) {
- "use strict";
-
+}(function (chai, utils) {
var slice = Array.prototype.slice;
+ var callsSuffix = "\n\n The following calls were made:\n%C";
+ var noCallsSuffix = ", but it was never called";
+
function isSpy(putativeSpy) {
return typeof putativeSpy === "function" &&
typeof putativeSpy.getCall === "function" &&
@@ -28,10 +31,20 @@
}
function timesInWords(count) {
- return count === 1 ? "once" :
- count === 2 ? "twice" :
- count === 3 ? "thrice" :
- (count || 0) + " times";
+ switch (count) {
+ case 1: {
+ return "once";
+ }
+ case 2: {
+ return "twice";
+ }
+ case 3: {
+ return "thrice";
+ }
+ default: {
+ return (count || 0) + " times";
+ }
+ }
}
function isCall(putativeCall) {
@@ -48,10 +61,20 @@
var verbPhrase = always ? "always have " : "have ";
passedSuffix = passedSuffix || "";
failedSuffix = failedSuffix || "";
+
if (isSpy(spy.proxy)) {
spy = spy.proxy;
}
+ if (spy.getCalls().length) {
+ // If there were calls, display them in case of a failure
+ failedSuffix += callsSuffix;
+ } else {
+ // Otherwise, replace the entire failed suffix with message that
+ // there were no calls
+ failedSuffix = noCallsSuffix;
+ }
+
function printfArray(array) {
return spy.printf.apply(spy, array);
}
@@ -97,9 +120,9 @@
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 sinonMethodName = shouldBeAlways ? alwaysSinonMethod : sinonName;
- var expression = this._obj[sinonMethod].apply(this._obj, arguments);
+ var expression = this._obj[sinonMethodName].apply(this._obj, arguments);
var passed = utils.test(this, [expression]);
var messages = getMessages(passed,
this._obj, action, passedSuffix, failedSuffix, shouldBeAlways, slice.call(arguments));
@@ -125,20 +148,20 @@
utils.flag(this, "always", true);
});
- var calls = "\n\n The following calls were made:\n%C";
-
- sinonProperty("called", "been called", " at least once", " at least once, but it was never called");
- sinonPropertyAsBooleanMethod("callCount", "been called exactly %1", "", ", but it was called %c" + calls);
- sinonProperty("calledOnce", "been called exactly once", "", ", but it was called %c" + calls);
- sinonProperty("calledTwice", "been called exactly twice", "", ", but it was called %c" + calls);
- sinonProperty("calledThrice", "been called exactly thrice", "", ", but it was called %c" + calls);
+ sinonProperty("called", "been called at least once");
+ sinonPropertyAsBooleanMethod("callCount", "been called exactly %1", "", ", but it was called %c");
+ sinonProperty("calledOnce", "been called exactly once", "", ", but it was called %c");
+ sinonProperty("calledTwice", "been called exactly twice", "", ", but it was called %c");
+ sinonProperty("calledThrice", "been called exactly thrice", "", ", but it was called %c");
sinonMethodAsProperty("calledWithNew", "been called with new");
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 %*", "", calls);
- sinonMethod("calledWithExactly", "been called with exact arguments %*", "", calls);
- sinonMethod("calledWithMatch", "been called with arguments matching %*", "", calls);
+ sinonMethod("calledWith", "been called with arguments %*");
+ sinonMethod("calledWithExactly", "been called with exact arguments %*");
+ sinonMethod("calledWithMatch", "been called with arguments matching %*");
+ sinonMethod("calledImmediatelyBefore", "been called immediately before %1");
+ sinonMethod("calledImmediatelyAfter", "been called immediately after %1");
sinonMethod("returned", "returned %1");
exceptionalSinonMethod("thrown", "threw", "thrown %1");
}));

LICENSE.txt

@@ -2,7 +2,7 @@
---
-Copyright © 2012–2015 Domenic Denicola <d@domenic.me>
+Copyright © 2012–2017 Domenic Denicola <d@domenic.me>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
@@ -24,7 +24,7 @@
---
-Copyright © 2012–2015, Domenic Denicola <d@domenic.me>
+Copyright © 2012–2017, Domenic Denicola <d@domenic.me>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,

package.json

@@ -13,7 +13,7 @@
"stubs",
"mocks"
],
- "version": "1.0.0",
+ "version": "1.1.0",
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
"license": "(BSD-2-Clause OR WTFPL)",
"repository": "domenic/sinon-chai",
@@ -23,32 +23,25 @@
],
"scripts": {
"pretest": "npm run lint",
- "test": "npm run test-chai-1-9-2 && npm run test-chai-2-3-0 && npm run test-chai-3-0-0",
- "test-current-chai": "mocha",
- "test-chai-1-9-2": "npm install chai@1.9.2 && mocha",
- "test-chai-2-3-0": "npm install chai@2.3.0 && mocha",
- "test-chai-3-0-0": "npm install chai@3.0.0 && mocha",
- "lint": "jshint ./lib",
+ "test": "mocha",
+ "test-travis": "npm install chai@$CHAI_VERSION && npm install sinon@$SINON_VERSION && npm test",
+ "lint": "eslint .",
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/sinon-chai.js.html",
"commit": "commit-wizard",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post"
},
- "peerDependencies": {
- "chai": ">=1.9.2 <4",
- "sinon": ">=1.4.0 <2"
- },
"devDependencies": {
- "chai": "^3.0.0",
+ "chai": "^4.0.2",
"coffee-script": "~1.8.0",
"condition-circle": "^1.5.0",
- "istanbul": "~0.3.2",
- "jshint": "^2.5.6",
- "mocha": "^1.21.4",
- "opener": "^1.4.0",
+ "eslint": "^3.19.0",
+ "istanbul": "~0.4.5",
+ "mocha": "^3.4.2",
+ "opener": "^1.4.3",
"pre-git": "^3.15.0",
"semantic-release": "^6.3.6",
- "simple-commit-message": "^3.0.2",
- "sinon": "^1.10.3"
+ "sinon": "^2.3.4",
+ "simple-commit-message": "^3.0.2"
},
"release": {
"verifyConditions": "condition-circle",
@@ -57,7 +50,9 @@
"config": {
"pre-git": {
"commit-msg": "simple",
- "pre-commit": [],
+ "pre-commit": [
+ "npm test"
+ ],
"pre-push": [],
"post-commit": [],
"post-checkout": [],

README.md

@@ -68,6 +68,14 @@
<td>spy1.should.have.been.calledAfter(spy2)</td>
</tr>
<tr>
+ <td>calledImmediatelyBefore</td>
+ <td>spy.should.have.been.calledImmediatelyBefore(spy2)</td>
+ </tr>
+ <tr>
+ <td>calledImmediatelyAfter</td>
+ <td>spy.should.have.been.calledImmediatelyAfter(spy2)</td>
+ </tr>
+ <tr>
<td>calledWithNew</td>
<td>spy.should.have.been.calledWithNew</td>
</tr>