Skip to content

Commit

Permalink
test: improve the code in test-process-hrtime
Browse files Browse the repository at this point in the history
* use const instead of var
* use assert.strictEqual instead of assert.equal and plain assert
* use arrow functions
* swap assertions arguments to match the standard
* validate the error for assert.throws
  • Loading branch information
edsadr committed Jan 8, 2017
1 parent 6d3c5b7 commit 7b47aef
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/parallel/test-process-hrtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('../common');
const assert = require('assert');

// the default behavior, return an Array "tuple" of numbers
var tuple = process.hrtime();
const tuple = process.hrtime();

// validate the default behavior
validateTuple(tuple);
Expand All @@ -12,16 +12,16 @@ validateTuple(tuple);
validateTuple(process.hrtime(tuple));

// test that only an Array may be passed to process.hrtime()
assert.throws(function() {
assert.throws(() => {
process.hrtime(1);
});
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);

function validateTuple(tuple) {
assert(Array.isArray(tuple));
assert.equal(2, tuple.length);
tuple.forEach(function(v) {
assert.equal('number', typeof v);
assert(isFinite(v));
assert.strictEqual(tuple.length, 2);
tuple.forEach((v) => {
assert.strictEqual(typeof v, 'number');
assert.strictEqual(isFinite(v), true);
});
}

Expand Down

0 comments on commit 7b47aef

Please sign in to comment.