From 27287b052d81eb19f196873a64933010c5a3016f Mon Sep 17 00:00:00 2001 From: Saud Khanzada Date: Tue, 4 Sep 2018 20:04:19 +0500 Subject: [PATCH] test: replaces assert.throws() with common.expectsError() replaces assert.throws() with common.expectsError() to check error code and error type in parallel/test-buffer-alloc.js --- test/parallel/test-buffer-alloc.js | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index f89e25fdbb2f92..023852b69a850a 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -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);