Skip to content

Commit a15de48

Browse files
mritunjayzMylesBorins
authored andcommitted
test: add property for RangeError in test-buffer-copy
PR-URL: #23968 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent d1ac802 commit a15de48

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

test/parallel/test-buffer-copy.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
const b = Buffer.allocUnsafe(1024);
77
const c = Buffer.allocUnsafe(512);
8+
9+
const errorProperty = {
10+
code: 'ERR_INDEX_OUT_OF_RANGE',
11+
type: RangeError,
12+
message: 'Index out of range'
13+
};
14+
815
let cntr = 0;
916

1017
{
@@ -107,9 +114,9 @@ bb.fill('hello crazy world');
107114
b.copy(c, 0, 100, 10);
108115

109116
// copy throws at negative sourceStart
110-
assert.throws(function() {
111-
Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1);
112-
}, RangeError);
117+
common.expectsError(
118+
() => Buffer.allocUnsafe(5).copy(Buffer.allocUnsafe(5), 0, -1),
119+
errorProperty);
113120

114121
{
115122
// check sourceEnd resets to targetEnd if former is greater than the latter
@@ -122,7 +129,8 @@ assert.throws(function() {
122129
}
123130

124131
// throw with negative sourceEnd
125-
assert.throws(() => b.copy(c, 0, 0, -1), RangeError);
132+
common.expectsError(
133+
() => b.copy(c, 0, -1), errorProperty);
126134

127135
// when sourceStart is greater than sourceEnd, zero copied
128136
assert.strictEqual(b.copy(c, 0, 100, 10), 0);

0 commit comments

Comments
 (0)