@@ -26,6 +26,7 @@ function Test(title, fn) {
26
26
this . assertCount = 0 ;
27
27
this . planCount = null ;
28
28
this . duration = null ;
29
+ this . assertError = undefined ;
29
30
30
31
// test type, can be: test, hook, eachHook
31
32
this . type = 'test' ;
@@ -67,20 +68,29 @@ Object.keys(assert).forEach(function (el) {
67
68
if ( isPromise ( fn ) ) {
68
69
return Promise . resolve ( fn )
69
70
. catch ( function ( err ) {
70
- self . assertError = err ;
71
+ self . _setAssertError ( err ) ;
71
72
} )
72
73
. finally ( function ( ) {
73
74
self . _assert ( ) ;
74
75
} ) ;
75
76
}
76
77
} catch ( err ) {
77
- this . assertError = err ;
78
+ this . _setAssertError ( err ) ;
78
79
}
79
80
80
81
this . _assert ( ) ;
81
82
} ;
82
83
} ) ;
83
84
85
+ Test . prototype . _setAssertError = function ( err ) {
86
+ if ( this . assertError === undefined ) {
87
+ if ( err === undefined ) {
88
+ err = 'undefined' ;
89
+ }
90
+ this . assertError = err ;
91
+ }
92
+ } ;
93
+
84
94
// Workaround for power-assert
85
95
// `t` must be capturable for decorated assert output
86
96
Test . prototype . _capt = assert . _capt ;
@@ -118,7 +128,7 @@ Test.prototype.run = function () {
118
128
try {
119
129
ret = this . fn ( this ) ;
120
130
} catch ( err ) {
121
- this . assertError = err ;
131
+ this . _setAssertError ( err ) ;
122
132
this . exit ( ) ;
123
133
}
124
134
@@ -132,11 +142,11 @@ Test.prototype.run = function () {
132
142
}
133
143
} )
134
144
. catch ( function ( err ) {
135
- self . assertError = new assert . AssertionError ( {
145
+ self . _setAssertError ( new assert . AssertionError ( {
136
146
actual : err ,
137
147
message : 'Promise rejected → ' + err ,
138
148
operator : 'promise'
139
- } ) ;
149
+ } ) ) ;
140
150
141
151
self . exit ( ) ;
142
152
} ) ;
@@ -147,11 +157,11 @@ Test.prototype.run = function () {
147
157
148
158
Test . prototype . end = function ( err ) {
149
159
if ( err ) {
150
- this . assertError = new assert . AssertionError ( {
160
+ this . _setAssertError ( new assert . AssertionError ( {
151
161
actual : err ,
152
162
message : 'Callback called with an error → ' + err ,
153
163
operator : 'callback'
154
- } ) ;
164
+ } ) ) ;
155
165
156
166
this . exit ( ) ;
157
167
return ;
@@ -174,13 +184,13 @@ Test.prototype.exit = function () {
174
184
// stop infinite timer
175
185
clearTimeout ( this . _timeout ) ;
176
186
177
- if ( ! this . assertError && this . planCount !== null && this . planCount !== this . assertCount ) {
178
- this . assertError = new assert . AssertionError ( {
187
+ if ( this . assertError === undefined && this . planCount !== null && this . planCount !== this . assertCount ) {
188
+ this . _setAssertError ( new assert . AssertionError ( {
179
189
actual : this . assertCount ,
180
190
expected : this . planCount ,
181
191
message : 'Assertion count does not match planned' ,
182
192
operator : 'plan'
183
- } ) ;
193
+ } ) ) ;
184
194
185
195
this . assertError . stack = this . planStack ;
186
196
}
@@ -189,7 +199,7 @@ Test.prototype.exit = function () {
189
199
this . ended = true ;
190
200
191
201
setImmediate ( function ( ) {
192
- if ( self . assertError ) {
202
+ if ( self . assertError !== undefined ) {
193
203
self . promise . reject ( self . assertError ) ;
194
204
return ;
195
205
}
0 commit comments