File tree Expand file tree Collapse file tree 2 files changed +10
-31
lines changed Expand file tree Collapse file tree 2 files changed +10
-31
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
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' ) ;
6
4
7
5
module . exports = ( sinon ) => {
8
6
check ( sinon ) ;
@@ -11,9 +9,15 @@ module.exports = (sinon) => {
11
9
const fn = sinon . stub ( ) ;
12
10
const { calledWith :original } = fn ;
13
11
14
- fn . calledWith = ( ...args ) => {
12
+ fn . calledWith = function ( ...args ) {
15
13
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
+ } ) ;
17
21
} ;
18
22
19
23
return fn ;
@@ -25,32 +29,9 @@ module.exports = (sinon) => {
25
29
} ;
26
30
} ;
27
31
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
-
47
32
function check ( sinon ) {
48
33
if ( typeof sinon !== 'object' )
49
34
throw Error ( 'sinon should be an object!' ) ;
50
35
51
36
}
52
37
53
- function write ( str ) {
54
- process . stdout . write ( chalk . red ( str ) + '\n' ) ;
55
- }
56
-
Original file line number Diff line number Diff line change 43
43
"tape" : " ^4.2.0"
44
44
},
45
45
"dependencies" : {
46
- "chalk" : " ^2.4.1" ,
47
- "jest-diff" : " ^23.6.0" ,
48
- "strip-ansi" : " ^5.0.0"
46
+ "@cloudcmd/stub" : " ^1.0.0"
49
47
},
50
48
"engines" : {
51
49
"node" : " >=8.3.0"
You can’t perform that action at this time.
0 commit comments