diff --git a/test/harness/assert.js b/test/harness/assert.js index 1d9d4a48f22903be816e05fba896b8a07dcb3555..2c1c884a3815496847173c821a7ee92f9303ffd2 100644 --- a/test/harness/assert.js +++ b/test/harness/assert.js @@ -40,3 +40,25 @@ assert.notSameValue = function (actual, unexpected, message) { } $ERROR(message); }; + +assert.throws = function (expectedErrorConstructor, func) { + if (func === undefined) { + $ERROR('assert.throws requires two arguments: the error constructor and a function to run'); + return; + } + + try { + func(); + } catch (thrown) { + if (typeof thrown !== 'object' || thrown === null) { + $ERROR('Thrown value was not an object!'); + return; + } + if (thrown.constructor !== expectedErrorConstructor) { + $ERROR('Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name); + } + return; + } + + $ERROR('Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all'); +}; diff --git a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js index 93e69c395dce0532b9cf992fa1aabc9cdd1c7c5b..1f163f0fa81561ab3f5a15a03710aaa8e7766982 100644 --- a/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js +++ b/test/suite/es6/ch25/25.4/25.4.3/25.4.3.1/S25.4.3.1_A2.2_T1.js @@ -6,9 +6,10 @@ info: > Promise throws TypeError when 'this' is constructed but unsettled promise author: Sam Mikes description: Promise.call(new Promise()) throws TypeError -negative: TypeError ---*/ var p = new Promise(function() {}); -Promise.call(p, function () {}); +assert.throws(TypeError, function () { + Promise.call(p, function () {}); +});