Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2803913003: Add options.omitErrorMessage for should.throw() (Closed)
Patch Set: Add [error message omitted] Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 /** 6 /**
7 * @fileOverview WebAudio layout test utility library. Built around W3C's 7 * @fileOverview WebAudio layout test utility library. Built around W3C's
8 * testharness.js. Includes asynchronous test task manager, 8 * testharness.js. Includes asynchronous test task manager,
9 * assertion utilities. 9 * assertion utilities.
10 * @dependency testharness.js 10 * @dependency testharness.js
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 /** 264 /**
265 * Check if |actual| operation wrapped in a function throws an exception 265 * Check if |actual| operation wrapped in a function throws an exception
266 * with a expected error type correctly. |expected| is optional. 266 * with a expected error type correctly. |expected| is optional.
267 * 267 *
268 * @example 268 * @example
269 * should(() => { let a = b; }, 'A bad code').throw(); 269 * should(() => { let a = b; }, 'A bad code').throw();
270 * should(() => { let c = d; }, 'Assigning d to c.') 270 * should(() => { let c = d; }, 'Assigning d to c.')
271 * .throw('ReferenceError'); 271 * .throw('ReferenceError');
272 * should(() => { let e = f; }, 'Assigning e to f.')
273 * .throw('ReferenceError', { omitErrorMessage: true });
272 * 274 *
273 * @result 275 * @result
274 * "PASS A bad code threw an exception of ReferenceError." 276 * "PASS A bad code threw an exception of ReferenceError: b is not
275 * "PASS Assigning d to c threw ReferenceError." 277 * defined."
278 * "PASS Assigning d to c threw ReferenceError: d is not defined."
279 * "PASS Assigning e to f threw ReferenceError: [error message
280 * omitted]."
276 */ 281 */
277 throw () { 282 throw () {
278 this._processArguments(arguments); 283 this._processArguments(arguments);
279 this._printActualForFailure = false; 284 this._printActualForFailure = false;
280 285
281 let didThrowCorrectly = false; 286 let didThrowCorrectly = false;
282 let passDetail, failDetail; 287 let passDetail, failDetail;
283 288
284 try { 289 try {
285 // This should throw. 290 // This should throw.
286 this._actual(); 291 this._actual();
287 // Catch did not happen, so the test is failed. 292 // Catch did not happen, so the test is failed.
288 failDetail = '${actual} did not throw an exception.'; 293 failDetail = '${actual} did not throw an exception.';
289 } catch (error) { 294 } catch (error) {
295 let errorMessage = this._options.omitErrorMessage
296 ? ': [error message omitted]'
297 : ': "' + error.message + '"';
290 if (this._expected === null || this._expected === undefined) { 298 if (this._expected === null || this._expected === undefined) {
291 // The expected error type was not given. 299 // The expected error type was not given.
292 didThrowCorrectly = true; 300 didThrowCorrectly = true;
293 passDetail = '${actual} threw ' + error.name + ': "' 301 passDetail = '${actual} threw ' + error.name + errorMessage + '.';
294 + error.message + '".';
295 } else if (error.name === this._expected) { 302 } else if (error.name === this._expected) {
296 // The expected error type match the actual one. 303 // The expected error type match the actual one.
297 didThrowCorrectly = true; 304 didThrowCorrectly = true;
298 passDetail = '${actual} threw ${expected}: "' 305 passDetail = '${actual} threw ${expected}' + errorMessage + '.';
299 + error.message + '".';
300 } else { 306 } else {
301 didThrowCorrectly = false; 307 didThrowCorrectly = false;
302 failDetail = '${actual} threw "' + error.name 308 failDetail = '${actual} threw "' + error.name
303 + '" instead of ${expected}.'; 309 + '" instead of ${expected}.';
304 } 310 }
305 } 311 }
306 312
307 return this._assert(didThrowCorrectly, passDetail, failDetail); 313 return this._assert(didThrowCorrectly, passDetail, failDetail);
308 } 314 }
309 315
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1275
1270 /** 1276 /**
1271 * Load file from a given URL and pass ArrayBuffer to the following promise. 1277 * Load file from a given URL and pass ArrayBuffer to the following promise.
1272 * See |loadFileFromUrl| method for the detail. 1278 * See |loadFileFromUrl| method for the detail.
1273 */ 1279 */
1274 loadFileFromUrl: loadFileFromUrl 1280 loadFileFromUrl: loadFileFromUrl
1275 1281
1276 }; 1282 };
1277 1283
1278 })(); 1284 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698