Skip to content

Commit d56db75

Browse files
committed
Don't leak internal AssertionErrors to user code
Asynchronous `t.throws()` / `t.notThrows()` was the only case where internal AssertionErrors were leaked to user code. Return `undefined` instead.
1 parent df54324 commit d56db75

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/assert.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ function wrapAssertions(callbacks) {
166166
};
167167

168168
if (promise) {
169-
const result = promise.then(makeNoop, makeRethrow).then(test);
170-
pending(this, result);
171-
return result;
169+
const intermediate = promise.then(makeNoop, makeRethrow).then(test);
170+
pending(this, intermediate);
171+
// Don't reject the returned promise, even if the assertion fails.
172+
return intermediate.catch(noop);
172173
}
173174

174175
try {
@@ -208,10 +209,10 @@ function wrapAssertions(callbacks) {
208209
};
209210

210211
if (promise) {
211-
const result = promise
212-
.then(noop, reason => test(makeRethrow(reason)));
213-
pending(this, result);
214-
return result;
212+
const intermediate = promise.then(noop, reason => test(makeRethrow(reason)));
213+
pending(this, intermediate);
214+
// Don't reject the returned promise, even if the assertion fails.
215+
return intermediate.catch(noop);
215216
}
216217

217218
try {

0 commit comments

Comments
 (0)