diff --git a/webaudio/resources/audit.js b/webaudio/resources/audit.js index 7ffa4392b05a15..2b83ae8d40a0a8 100644 --- a/webaudio/resources/audit.js +++ b/webaudio/resources/audit.js @@ -274,21 +274,23 @@ window.Audit = (function() { /** * Check if |actual| operation wrapped in a function throws an exception - * with a expected error type correctly. |expected| is optional. If it is a - * String, then it is considered to be the name of a DOMException. It can - * also be an instance of either an Error or a DOMException, to be more - * strict about the actual error type. + * with a expected error type correctly. |expected| is optional. If it is an + * instance of DOMException, then the description can be provided to be more + * strict about the exception type. It also can be other error types. * * @example * should(() => { let a = b; }, 'A bad code').throw(); - * should(() => { let c = d; }, 'Assigning d to c.') - * .throw('ReferenceError'); - * should(() => { let e = f; }, 'Assigning e to f.') - * .throw('ReferenceError', { omitErrorMessage: true }); + * should(() => { new SomeConstructor(); }, 'A bad construction') + * .throw(DOMException, 'NotSupportedError'); + * should(() => { let c = d; }, 'Assigning d to c') + * .throw(ReferenceError); + * should(() => { let e = f; }, 'Assigning e to f') + * .throw(ReferenceError, { omitErrorMessage: true }); * * @result * "PASS A bad code threw an exception of ReferenceError: b is not * defined." + * "PASS A bad construction threw NotSupportedError." * "PASS Assigning d to c threw ReferenceError: d is not defined." * "PASS Assigning e to f threw ReferenceError: [error message * omitted]." @@ -313,17 +315,15 @@ window.Audit = (function() { // The expected error type was not given. didThrowCorrectly = true; passDetail = '${actual} threw ' + error.name + errorMessage + '.'; - } else if (typeof(this._expected) == "string" && - error instanceof DOMException && - error.name === this._expected) { - // A DOMException was thrown and expected, and the names match + } else if (this._expected === DOMException && + this._expectedDescription === error.name) { + // Handles DOMException with the associated name. didThrowCorrectly = true; passDetail = '${actual} threw ${expected}' + errorMessage + '.'; - } else if (this._expected == error.constructor && - this._expected.name == error.name) { - // The expected error type and names match the actual one. + } else if (this._expected == error.constructor) { + // Handles other error types. didThrowCorrectly = true; - passDetail = '${actual} threw ${expected}' + errorMessage + '.'; + passDetail = '${actual} threw ' + error.name + errorMessage + '.'; } else { didThrowCorrectly = false; failDetail =