Skip to content

Commit e51a76b

Browse files
committed
feature(sinon-called-with-diff) calledWith -> @cloudcmd/stub
1 parent 0bbd7b6 commit e51a76b

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

lib/sinon-called-with-diff.js

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
const diff = require('jest-diff');
4-
const strip = require('strip-ansi');
5-
const chalk = require('chalk');
3+
const calledWith = require('@cloudcmd/stub/lib/called-with');
64

75
module.exports = (sinon) => {
86
check(sinon);
@@ -11,9 +9,15 @@ module.exports = (sinon) => {
119
const fn = sinon.stub();
1210
const {calledWith:original} = fn;
1311

14-
fn.calledWith = (...args) => {
12+
fn.calledWith = function (...args) {
1513
original.apply(fn, args);
16-
return calledWith.apply(fn, args);
14+
const calledArgs = this.args[this.args.length - 1];
15+
16+
return calledWith({
17+
called: fn.called,
18+
args,
19+
calledArgs,
20+
});
1721
};
1822

1923
return fn;
@@ -25,32 +29,9 @@ module.exports = (sinon) => {
2529
};
2630
};
2731

28-
function calledWith(...args) {
29-
if (!this.called) {
30-
write(`expected to call with ${JSON.stringify(args)}, but not called at all\n`);
31-
return false;
32-
}
33-
34-
const actual = this.args[this.args.length - 1];
35-
36-
const msg = diff(actual, args);
37-
const striped = strip(msg);
38-
39-
if (striped === 'Compared values have no visual difference.')
40-
return true;
41-
42-
console.log(msg);
43-
44-
return false;
45-
}
46-
4732
function check(sinon) {
4833
if (typeof sinon !== 'object')
4934
throw Error('sinon should be an object!');
5035

5136
}
5237

53-
function write(str) {
54-
process.stdout.write(chalk.red(str) + '\n');
55-
}
56-

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
"tape": "^4.2.0"
4444
},
4545
"dependencies": {
46-
"chalk": "^2.4.1",
47-
"jest-diff": "^23.6.0",
48-
"strip-ansi": "^5.0.0"
46+
"@cloudcmd/stub": "^1.0.0"
4947
},
5048
"engines": {
5149
"node": ">=8.3.0"

0 commit comments

Comments
 (0)