Skip to content

Commit a024104

Browse files
vinimdocarmoedsadr
authored andcommitted
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: #10908 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Adrian Estrada <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent ff75e21 commit a024104

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,27 @@ assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
3737
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
3838
.split(' ')
3939
.forEach(function(flags) {
40-
assert.throws(function() { stringToFlags(flags); });
40+
assert.throws(
41+
() => stringToFlags(flags),
42+
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
43+
);
4144
});
4245

4346
assert.throws(
4447
() => stringToFlags({}),
45-
/Unknown file open flag: \[object Object\]/
48+
/^Error: Unknown file open flag: \[object Object\]$/
4649
);
4750

4851
assert.throws(
4952
() => stringToFlags(true),
50-
/Unknown file open flag: true/
53+
/^Error: Unknown file open flag: true$/
5154
);
5255

5356
assert.throws(
5457
() => stringToFlags(null),
55-
/Unknown file open flag: null/
58+
/^Error: Unknown file open flag: null$/
5659
);
60+
61+
function escapeRegExp(string) {
62+
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
63+
}

0 commit comments

Comments
 (0)