Skip to content

Commit 6020e72

Browse files
vinimdocarmoMylesBorins
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 <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>
1 parent e6d6a41 commit 6020e72

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
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)