diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index 2c8eceb4095ceb..c59e0ab31c1667 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/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') .split(' ') .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( () => fs._stringToFlags({}), - /Unknown file open flag: \[object Object\]/ + /^Error: Unknown file open flag: \[object Object\]$/ ); assert.throws( () => fs._stringToFlags(true), - /Unknown file open flag: true/ + /^Error: Unknown file open flag: true$/ ); assert.throws( () => fs._stringToFlags(null), - /Unknown file open flag: null/ + /Error: Unknown file open flag: null$/ ); + +function escapeRegExp(string) { + return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); +}