Skip to content

Commit

Permalink
test: improve test-fs-open-flags
Browse files Browse the repository at this point in the history
* use arrow funcion instead of function expression
* add second argument to method assert.throws
* check error messages from beginning to the end using ^ and $

PR-URL: #10908
Backport-PR-URL: #13785
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Adrian Estrada <edsadr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
vinimdocarmo authored and gibfahn committed Jun 19, 2017
1 parent b690537 commit a5b8d1b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,27 @@ assert.strictEqual(fs._stringToFlags('xa+'),
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ')
.forEach(function(flags) {
assert.throws(function() { fs._stringToFlags(flags); });
assert.throws(
() => fs._stringToFlags(flags),
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
);
});

assert.throws(
() => fs._stringToFlags({}),
/Unknown file open flag: \[object Object\]/
/^Error: Unknown file open flag: \[object Object\]$/
);

assert.throws(
() => fs._stringToFlags(true),
/Unknown file open flag: true/
/^Error: Unknown file open flag: true$/
);

assert.throws(
() => fs._stringToFlags(null),
/Unknown file open flag: null/
/Error: Unknown file open flag: null$/
);

function escapeRegExp(string) {
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}

0 comments on commit a5b8d1b

Please sign in to comment.