OLD | NEW |
---|---|
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 Loading... | |
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." | |
276 */ | 280 */ |
277 throw () { | 281 throw () { |
278 this._processArguments(arguments); | 282 this._processArguments(arguments); |
279 this._printActualForFailure = false; | 283 this._printActualForFailure = false; |
280 | 284 |
281 let didThrowCorrectly = false; | 285 let didThrowCorrectly = false; |
282 let passDetail, failDetail; | 286 let passDetail, failDetail; |
283 | 287 |
284 try { | 288 try { |
285 // This should throw. | 289 // This should throw. |
286 this._actual(); | 290 this._actual(); |
287 // Catch did not happen, so the test is failed. | 291 // Catch did not happen, so the test is failed. |
288 failDetail = '${actual} did not throw an exception.'; | 292 failDetail = '${actual} did not throw an exception.'; |
289 } catch (error) { | 293 } catch (error) { |
294 let errorMessage = this._options.omitErrorMessage | |
295 ? '' | |
Raymond Toy
2017/04/06 20:06:59
If omitErrorMessage is true, perhaps we want to ou
hongchan
2017/04/06 20:38:17
Done.
| |
296 : ': "' + error.message + '"'; | |
290 if (this._expected === null || this._expected === undefined) { | 297 if (this._expected === null || this._expected === undefined) { |
291 // The expected error type was not given. | 298 // The expected error type was not given. |
292 didThrowCorrectly = true; | 299 didThrowCorrectly = true; |
293 passDetail = '${actual} threw ' + error.name + ': "' | 300 passDetail = '${actual} threw ' + error.name + errorMessage + '.'; |
294 + error.message + '".'; | |
295 } else if (error.name === this._expected) { | 301 } else if (error.name === this._expected) { |
296 // The expected error type match the actual one. | 302 // The expected error type match the actual one. |
297 didThrowCorrectly = true; | 303 didThrowCorrectly = true; |
298 passDetail = '${actual} threw ${expected}: "' | 304 passDetail = '${actual} threw ${expected}' + errorMessage + '.'; |
299 + error.message + '".'; | |
300 } else { | 305 } else { |
301 didThrowCorrectly = false; | 306 didThrowCorrectly = false; |
302 failDetail = '${actual} threw "' + error.name | 307 failDetail = '${actual} threw "' + error.name |
303 + '" instead of ${expected}.'; | 308 + '" instead of ${expected}.'; |
304 } | 309 } |
305 } | 310 } |
306 | 311 |
307 return this._assert(didThrowCorrectly, passDetail, failDetail); | 312 return this._assert(didThrowCorrectly, passDetail, failDetail); |
308 } | 313 } |
309 | 314 |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1269 | 1274 |
1270 /** | 1275 /** |
1271 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1276 * Load file from a given URL and pass ArrayBuffer to the following promise. |
1272 * See |loadFileFromUrl| method for the detail. | 1277 * See |loadFileFromUrl| method for the detail. |
1273 */ | 1278 */ |
1274 loadFileFromUrl: loadFileFromUrl | 1279 loadFileFromUrl: loadFileFromUrl |
1275 | 1280 |
1276 }; | 1281 }; |
1277 | 1282 |
1278 })(); | 1283 })(); |
OLD | NEW |