Skip to content

Commit f51d4f3

Browse files
edsadrlpinca
authored andcommitted
test: validate errors in test-buffer-indexof
* validate errors in assert.throws * use arrow functions PR-URL: #10752 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 77be180 commit f51d4f3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

test/parallel/test-buffer-indexof.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,20 @@ assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
344344
}
345345
}
346346

347-
assert.throws(function() {
348-
b.indexOf(function() { });
349-
});
350-
assert.throws(function() {
347+
const argumentExpected =
348+
/^TypeError: "val" argument must be string, number, Buffer or Uint8Array$/;
349+
350+
assert.throws(() => {
351+
b.indexOf(() => { });
352+
}, argumentExpected);
353+
354+
assert.throws(() => {
351355
b.indexOf({});
352-
});
353-
assert.throws(function() {
356+
}, argumentExpected);
357+
358+
assert.throws(() => {
354359
b.indexOf([]);
355-
});
360+
}, argumentExpected);
356361

357362
// All code for handling encodings is shared between Buffer.indexOf and
358363
// Buffer.lastIndexOf, so only testing the separate lastIndexOf semantics.

0 commit comments

Comments
 (0)