test: refactor test-fs-read-*

* Use `common.mustNotCall()` in place of `common.noop` where appropriate
* Increase specificity of regular expressions (that is, make them match
  the whole error string rather than part of the error string) in
  `assert.throws()` calls

PR-URL: https://github.com/nodejs/node/pull/13501
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
Rich Trott 2017-06-06 09:53:32 -07:00
parent 6318078d2c
commit 7fbeebac96
2 changed files with 5 additions and 5 deletions

View File

@ -8,6 +8,6 @@ const encoding = 'foo-8';
const filename = 'bar.txt';
assert.throws(
fs.readFile.bind(fs, filename, { encoding }, common.noop),
new RegExp(`Error: Unknown encoding: ${encoding}$`)
fs.readFile.bind(fs, filename, { encoding }, common.mustNotCall()),
new RegExp(`^Error: Unknown encoding: ${encoding}$`)
);

View File

@ -13,9 +13,9 @@ assert.throws(() => {
expected.length,
0,
'utf-8',
common.noop);
}, /Second argument needs to be a buffer/);
common.mustNotCall());
}, /^TypeError: Second argument needs to be a buffer$/);
assert.throws(() => {
fs.readSync(fd, expected.length, 0, 'utf-8');
}, /Second argument needs to be a buffer/);
}, /^TypeError: Second argument needs to be a buffer$/);