Skip to content

Commit

Permalink
test: replaces assert.throws() with common.expectsError()
Browse files Browse the repository at this point in the history
replaces assert.throws() with common.expectsError() to check error code
and error type in parallel/test-buffer-alloc.js

PR-URL: #22689
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Saud Khanzada authored and targos committed Sep 9, 2018
1 parent a7e8949 commit 3666662
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,40 @@ new Buffer('', 'binary');
Buffer(0);

// try to write a 0-length string beyond the end of b
assert.throws(() => b.write('', 2048), RangeError);
common.expectsError(
() => b.write('', 2048),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing to negative offset
assert.throws(() => b.write('a', -1), RangeError);
common.expectsError(
() => b.write('a', -1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing past bounds from the pool
assert.throws(() => b.write('a', 2048), RangeError);
common.expectsError(
() => b.write('a', 2048),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// throw when writing to negative offset
assert.throws(() => b.write('a', -1), RangeError);
common.expectsError(
() => b.write('a', -1),
{
code: 'ERR_BUFFER_OUT_OF_BOUNDS',
type: RangeError
}
);

// try to copy 0 bytes worth of data into an empty buffer
b.copy(Buffer.alloc(0), 0, 0, 0);
Expand Down

0 comments on commit 3666662

Please sign in to comment.