From 9ca85614630905f74ad4cb271348deafeddb3065 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 30 Aug 2016 19:38:32 -0700 Subject: [PATCH 1/2] test: test non-buffer/string with zlib Check the error condition testing for passing something other than a string or buffer. Currently, there are no tests for this. --- test/parallel/test-zlib-not-string-or-buffer.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/parallel/test-zlib-not-string-or-buffer.js diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js new file mode 100644 index 00000000000000..aa4ecc93450059 --- /dev/null +++ b/test/parallel/test-zlib-not-string-or-buffer.js @@ -0,0 +1,11 @@ +'use strict'; + +// Check the error condition testing for passing something other than a string +// or buffer. + +require('../common'); +const assert = require('assert'); +const zlib = require('zlib'); + +// Passing nothing (undefined) instead of string/buffer to `zlib.deflateSync()` +assert.throws(zlib.deflateSync, /^TypeError: Not a string or buffer$/); From d523efebde6977a5d6da83f8c73a0bd137741f6c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 1 Sep 2016 22:57:49 -0700 Subject: [PATCH 2/2] squash: add more types --- test/parallel/test-zlib-not-string-or-buffer.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-zlib-not-string-or-buffer.js b/test/parallel/test-zlib-not-string-or-buffer.js index aa4ecc93450059..3f58583e034ca8 100644 --- a/test/parallel/test-zlib-not-string-or-buffer.js +++ b/test/parallel/test-zlib-not-string-or-buffer.js @@ -7,5 +7,13 @@ require('../common'); const assert = require('assert'); const zlib = require('zlib'); -// Passing nothing (undefined) instead of string/buffer to `zlib.deflateSync()` -assert.throws(zlib.deflateSync, /^TypeError: Not a string or buffer$/); +const expected = /^TypeError: Not a string or buffer$/; + +assert.throws(() => { zlib.deflateSync(undefined); }, expected); +assert.throws(() => { zlib.deflateSync(null); }, expected); +assert.throws(() => { zlib.deflateSync(true); }, expected); +assert.throws(() => { zlib.deflateSync(false); }, expected); +assert.throws(() => { zlib.deflateSync(0); }, expected); +assert.throws(() => { zlib.deflateSync(1); }, expected); +assert.throws(() => { zlib.deflateSync([1, 2, 3]); }, expected); +assert.throws(() => { zlib.deflateSync({foo: 'bar'}); }, expected);