From d6b415322cdf76569f4eec7e1f10f48ceee4a249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20do=20Carmo?= Date: Thu, 19 Jan 2017 23:01:01 -0300 Subject: [PATCH] test: improve test-fs-open-flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: nodejs#10908 Reviewed-By: Rich Trott Reviewed-By: Adrian Estrada Reviewed-By: Luigi Pinca Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig --- test/parallel/test-fs-open-flags.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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, '\\$&'); +}