Browse Source

test: improve test-fs-open-flags

* 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: https://github.com/nodejs/node/pull/10908
Backport-PR-URL: https://github.com/nodejs/node/pull/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>
v6.x
Vinícius do Carmo 8 years ago
committed by Myles Borins
parent
commit
6020e720b5
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 15
      test/parallel/test-fs-open-flags.js

15
test/parallel/test-fs-open-flags.js

@ -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') ('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ') .split(' ')
.forEach(function(flags) { .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( assert.throws(
() => fs._stringToFlags({}), () => fs._stringToFlags({}),
/Unknown file open flag: \[object Object\]/ /^Error: Unknown file open flag: \[object Object\]$/
); );
assert.throws( assert.throws(
() => fs._stringToFlags(true), () => fs._stringToFlags(true),
/Unknown file open flag: true/ /^Error: Unknown file open flag: true$/
); );
assert.throws( assert.throws(
() => fs._stringToFlags(null), () => fs._stringToFlags(null),
/Unknown file open flag: null/ /Error: Unknown file open flag: null$/
); );
function escapeRegExp(string) {
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}

Loading…
Cancel
Save