diff --git a/src/assert.js b/src/assert.js index 69e5fe685..7b6a5f65c 100644 --- a/src/assert.js +++ b/src/assert.js @@ -373,41 +373,39 @@ class Assert { }, function handleRejection( actual ) { - if ( actual ) { - const expectedType = objectType( expected ); - - // We don't want to validate - if ( expected === undefined ) { - result = true; + const expectedType = objectType( expected ); + + // We don't want to validate + if ( expected === undefined ) { + result = true; + expected = actual; + + // Expected is a regexp + } else if ( expectedType === "regexp" ) { + result = expected.test( errorString( actual ) ); + + // Expected is a constructor, maybe an Error constructor + } else if ( expectedType === "function" && actual instanceof expected ) { + result = true; + + // Expected is an Error object + } else if ( expectedType === "object" ) { + result = actual instanceof expected.constructor && + actual.name === expected.name && + actual.message === expected.message; + + // Expected is a validation function which returns true if validation passed + } else { + if ( expectedType === "function" ) { + result = expected.call( {}, actual ) === true; expected = null; - // Expected is a regexp - } else if ( expectedType === "regexp" ) { - result = expected.test( errorString( actual ) ); - - // Expected is a constructor, maybe an Error constructor - } else if ( expectedType === "function" && actual instanceof expected ) { - result = true; - - // Expected is an Error object - } else if ( expectedType === "object" ) { - result = actual instanceof expected.constructor && - actual.name === expected.name && - actual.message === expected.message; - - // Expected is a validation function which returns true if validation passed + // Expected is some other invalid type } else { - if ( expectedType === "function" ) { - result = expected.call( {}, actual ) === true; - expected = null; - - // Expected is some other invalid type - } else { - result = false; - message = "invalid expected value provided to `assert.rejects` " + - "callback in \"" + currentTest.testName + "\": " + - expectedType + "."; - } + result = false; + message = "invalid expected value provided to `assert.rejects` " + + "callback in \"" + currentTest.testName + "\": " + + expectedType + "."; } } diff --git a/test/main/assert.js b/test/main/assert.js index 354598981..59bff34b7 100644 --- a/test/main/assert.js +++ b/test/main/assert.js @@ -287,7 +287,7 @@ QUnit.test( "throws", function( assert ) { } ); QUnit.test( "rejects", function( assert ) { - assert.expect( 15 ); + assert.expect( 16 ); function CustomError( message ) { this.message = message; @@ -396,6 +396,11 @@ QUnit.test( "rejects", function( assert ) { /description/, "throw error from property of 'this' context" ); + + assert.rejects( + buildMockPromise( undefined ), + "reject with undefined against no matcher" + ); } ); QUnit.test( "raises, alias for throws", function( assert ) {