Skip to content

Commit aa4b028

Browse files
vinimdocarmoitaloacasas
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 35d6659 commit aa4b028

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
@@ -34,20 +34,27 @@ assert.equal(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
3434
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
3535
.split(' ')
3636
.forEach(function(flags) {
37-
assert.throws(function() { stringToFlags(flags); });
37+
assert.throws(
38+
() => stringToFlags(flags),
39+
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
40+
);
3841
});
3942

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

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

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

0 commit comments

Comments
 (0)