|
407 | 407 |
|
408 | 408 | /*--------------------------------------------------------------------------*/ |
409 | 409 |
|
| 410 | + QUnit.module('Benchmark.toString'); |
| 411 | + |
| 412 | + (() => { |
| 413 | + QUnit.test('should format a thrown error', (assert) => { |
| 414 | + var bench = new Benchmark({ |
| 415 | + fn: 'const x=42;x.foo()', |
| 416 | + }).run(); |
| 417 | + |
| 418 | + assert.ok(!!bench.error); |
| 419 | + assert.ok(bench.error instanceof Error); |
| 420 | + assert.ok(bench.error.message.includes('x.foo is not a function')); |
| 421 | + assert.ok(bench.toString().includes('x.foo is not a function')); |
| 422 | + }); |
| 423 | + QUnit.test('should format a manually-set function error', (assert) => { |
| 424 | + var bench = new Benchmark({ |
| 425 | + fn: 'this.error = () => {console.log("foo")}; this.error.toString = () => "manual stringification";', |
| 426 | + }).run(); |
| 427 | + |
| 428 | + assert.ok(!!bench.error); |
| 429 | + assert.equal(typeof bench.error, 'function'); |
| 430 | + assert.ok(bench.toString().endsWith('() => "manual stringification"')); |
| 431 | + }); |
| 432 | + QUnit.test('should format a manually-set number error', (assert) => { |
| 433 | + var bench = new Benchmark({ |
| 434 | + fn: 'this.error = 42;', |
| 435 | + }).run(); |
| 436 | + |
| 437 | + assert.ok(!!bench.error); |
| 438 | + assert.equal(typeof bench.error, 'number'); |
| 439 | + assert.equal(bench.toString(), `<Test #${bench.id}>: 42`); |
| 440 | + }); |
| 441 | + })(); |
| 442 | + |
| 443 | + /*--------------------------------------------------------------------------*/ |
| 444 | + |
410 | 445 | QUnit.module('Benchmark#clone'); |
411 | 446 |
|
412 | 447 | (function() { |
|
0 commit comments