Skip to content

Commit 0f3cef5

Browse files
committed
increase coverage of Benchmark.join()
1 parent 849a7ce commit 0f3cef5

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

test/test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,41 @@
407407

408408
/*--------------------------------------------------------------------------*/
409409

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+
410445
QUnit.module('Benchmark#clone');
411446

412447
(function() {

0 commit comments

Comments
 (0)