summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-indexof.js
diff options
context:
space:
mode:
authorWeijia Wang <381152119@qq.com>2017-08-22 19:57:26 +0800
committerJames M Snell <jasnell@gmail.com>2017-08-24 14:49:47 -0700
commit9e0f771224759484bd95358f02de650916287488 (patch)
treeaba239ccc9c9f6988843d04483bffd7ddb63a527 /test/parallel/test-buffer-indexof.js
parent52fe7626068c7110696104139a063942bdb3fd83 (diff)
downloadandroid-node-v8-9e0f771224759484bd95358f02de650916287488.tar.gz
android-node-v8-9e0f771224759484bd95358f02de650916287488.tar.bz2
android-node-v8-9e0f771224759484bd95358f02de650916287488.zip
buffer: improve error messages
Some errors in buffer module losed some arguments or received wrong arguments when they were created. This PR added these losing arguments and fixed the wrong arguments. PR-URL: https://github.com/nodejs/node/pull/14975 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-indexof.js')
-rw-r--r--test/parallel/test-buffer-indexof.js33
1 files changed, 15 insertions, 18 deletions
diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js
index f5a15de2c5..6e24b61478 100644
--- a/test/parallel/test-buffer-indexof.js
+++ b/test/parallel/test-buffer-indexof.js
@@ -344,24 +344,21 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
}
}
-const argumentExpected = common.expectsError({
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "val" argument must be one of type ' +
- 'string, buffer, or uint8Array'
-}, 3);
-
-assert.throws(() => {
- b.indexOf(() => { });
-}, argumentExpected);
-
-assert.throws(() => {
- b.indexOf({});
-}, argumentExpected);
-
-assert.throws(() => {
- b.indexOf([]);
-}, argumentExpected);
+[
+ () => {},
+ {},
+ []
+].forEach((val) => {
+ common.expectsError(
+ () => b.indexOf(val),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'The "value" argument must be one of type string, ' +
+ `buffer, or uint8Array. Received type ${typeof val}`
+ }
+ );
+});
// Test weird offset arguments.
// The following offsets coerce to NaN or 0, searching the whole Buffer