Skip to content

Commit a5b8d1b

Browse files
vinimdocarmogibfahn
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 Backport-PR-URL: #13785 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 b690537 commit a5b8d1b

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
@@ -39,20 +39,27 @@ assert.strictEqual(fs._stringToFlags('xa+'),
3939
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
4040
.split(' ')
4141
.forEach(function(flags) {
42-
assert.throws(function() { fs._stringToFlags(flags); });
42+
assert.throws(
43+
() => fs._stringToFlags(flags),
44+
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
45+
);
4346
});
4447

4548
assert.throws(
4649
() => fs._stringToFlags({}),
47-
/Unknown file open flag: \[object Object\]/
50+
/^Error: Unknown file open flag: \[object Object\]$/
4851
);
4952

5053
assert.throws(
5154
() => fs._stringToFlags(true),
52-
/Unknown file open flag: true/
55+
/^Error: Unknown file open flag: true$/
5356
);
5457

5558
assert.throws(
5659
() => fs._stringToFlags(null),
57-
/Unknown file open flag: null/
60+
/Error: Unknown file open flag: null$/
5861
);
62+
63+
function escapeRegExp(string) {
64+
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
65+
}

0 commit comments

Comments
 (0)