@@ -34,47 +34,55 @@ module.exports = error => {
34
34
. join ( '\n\n' ) + '\n' ;
35
35
}
36
36
37
- if ( error . actual && error . expected ) {
38
- if ( error . actual . type === error . expected . type ) {
39
- const type = error . actual . type ;
40
- if ( type === 'array' || type === 'object' ) {
41
- const patch = diff . createPatch ( 'string' , error . actual . formatted , error . expected . formatted ) ;
42
- const msg = patch
43
- . split ( '\n' )
44
- . slice ( 4 )
45
- . map ( cleanUp )
46
- . filter ( Boolean )
47
- . join ( '\n' )
48
- . trimRight ( ) ;
37
+ if ( error . actual && error . expected && error . actual . type === error . expected . type ) {
38
+ const type = error . actual . type ;
39
+ if ( type === 'array' || type === 'object' ) {
40
+ const patch = diff . createPatch ( 'string' , error . actual . formatted , error . expected . formatted ) ;
41
+ const msg = patch
42
+ . split ( '\n' )
43
+ . slice ( 4 )
44
+ . map ( cleanUp )
45
+ . filter ( Boolean )
46
+ . join ( '\n' )
47
+ . trimRight ( ) ;
49
48
50
- return `Difference:\n\n${ msg } \n` ;
51
- }
49
+ return `Difference:\n\n${ msg } \n` ;
50
+ }
52
51
53
- if ( type === 'string' ) {
54
- const diffMatchPatch = new DiffMatchPatch ( ) ;
55
- const patch = diffMatchPatch . diff_main ( stripAnsi ( error . actual . formatted ) , stripAnsi ( error . expected . formatted ) ) ;
56
- const msg = patch
57
- . map ( part => {
58
- if ( part [ 0 ] === 1 ) {
59
- return chalk . bgGreen . black ( part [ 1 ] ) ;
60
- }
52
+ if ( type === 'string' ) {
53
+ const diffMatchPatch = new DiffMatchPatch ( ) ;
54
+ const patch = diffMatchPatch . diff_main ( stripAnsi ( error . actual . formatted ) , stripAnsi ( error . expected . formatted ) ) ;
55
+ const msg = patch
56
+ . map ( part => {
57
+ if ( part [ 0 ] === 1 ) {
58
+ return chalk . bgGreen . black ( part [ 1 ] ) ;
59
+ }
61
60
62
- if ( part [ 0 ] === - 1 ) {
63
- return chalk . bgRed . black ( part [ 1 ] ) ;
64
- }
61
+ if ( part [ 0 ] === - 1 ) {
62
+ return chalk . bgRed . black ( part [ 1 ] ) ;
63
+ }
65
64
66
- return chalk . red ( part [ 1 ] ) ;
67
- } )
68
- . join ( '' )
69
- . trimRight ( ) ;
65
+ return chalk . red ( part [ 1 ] ) ;
66
+ } )
67
+ . join ( '' )
68
+ . trimRight ( ) ;
70
69
71
- return `Difference:\n\n${ msg } \n` ;
72
- }
70
+ return `Difference:\n\n${ msg } \n` ;
73
71
}
72
+ }
74
73
75
- return `Actual:\n\n${ indentString ( error . actual . formatted , 2 ) . trimRight ( ) } \n\n` +
76
- `Expected:\n\n${ indentString ( error . expected . formatted , 2 ) . trimRight ( ) } \n` ;
74
+ let retval = null ;
75
+ if ( error . actual ) {
76
+ retval = `Actual:\n\n${ indentString ( error . actual . formatted , 2 ) . trimRight ( ) } \n` ;
77
+ }
78
+ if ( error . expected ) {
79
+ if ( retval ) {
80
+ retval += '\n' ;
81
+ } else {
82
+ retval = '' ;
83
+ }
84
+ retval += `Expected:\n\n${ indentString ( error . expected . formatted , 2 ) . trimRight ( ) } \n` ;
77
85
}
78
86
79
- return null ;
87
+ return retval ;
80
88
} ;
0 commit comments