@@ -112,6 +112,10 @@ function Test(name_, opts_, cb_) {
112112
113113inherits ( Test , EventEmitter ) ;
114114
115+ function isPromiseLike ( x ) {
116+ return x && typeof x . then === 'function' ;
117+ }
118+
115119Test . prototype . run = function run ( ) {
116120 this . emit ( 'prerun' ) ;
117121 if ( ! this . _cb || this . _skip ) {
@@ -124,11 +128,7 @@ Test.prototype.run = function run() {
124128
125129 var callbackReturn = this . _cb ( this ) ;
126130
127- if (
128- typeof Promise === 'function'
129- && callbackReturn
130- && typeof callbackReturn . then === 'function'
131- ) {
131+ if ( typeof Promise === 'function' && isPromiseLike ( callbackReturn ) ) {
132132 var self = this ;
133133 Promise . resolve ( callbackReturn ) . then (
134134 function onResolve ( ) {
@@ -423,7 +423,7 @@ Test.prototype._end = function _end(err) {
423423 } catch ( e ) {
424424 self . fail ( e ) ;
425425 }
426- if ( res && typeof res . then === 'function' ) {
426+ if ( isPromiseLike ( res ) ) {
427427 res . then ( next , function ( _err ) {
428428 // TODO: wth?
429429 err = err || _err ;
@@ -811,6 +811,8 @@ function notDeepLooseEqual(a, b, msg, extra) {
811811Test . prototype . notDeepLooseEqual
812812= notDeepLooseEqual ;
813813
814+ var isObject = require ( './isObject' ) ;
815+
814816Test . prototype [ 'throws' ] = function ( fn , expected , msg , extra ) {
815817 if ( typeof expected === 'string' ) {
816818 msg = expected ;
@@ -823,7 +825,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
823825 fn ( ) ;
824826 } catch ( err ) {
825827 caught = { error : err } ;
826- if ( Object ( err ) === err && 'message' in err && ( ! isEnumerable ( err , 'message' ) || ! hasOwn ( err , 'message' ) ) ) {
828+ if ( isObject ( err ) && 'message' in err && ( ! isEnumerable ( err , 'message' ) || ! hasOwn ( err , 'message' ) ) ) {
827829 try {
828830 var message = err . message ;
829831 delete err . message ;
0 commit comments