Skip to content

Commit

Permalink
test: improve test-fs-write-stream-throw-type
Browse files Browse the repository at this point in the history
* validate the errors for all assert.throws
* use arrow functions

PR-URL: #10779
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
edsadr authored and jasnell committed Jan 16, 2017
1 parent 8628c93 commit 1699a8a
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions test/parallel/test-fs-write-stream-throw-type-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,44 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const numberError = new RegExp('^TypeError: "options" must be a string ' +
'or an object, got number instead.$');

const booleanError = new RegExp('^TypeError: "options" must be a string ' +
'or an object, got boolean instead.$');

const example = path.join(common.tmpDir, 'dummy');

common.refreshTmpDir();

assert.doesNotThrow(function() {
assert.doesNotThrow(() => {
fs.createWriteStream(example, undefined);
});
assert.doesNotThrow(function() {

assert.doesNotThrow(() => {
fs.createWriteStream(example, null);
});
assert.doesNotThrow(function() {

assert.doesNotThrow(() => {
fs.createWriteStream(example, 'utf8');
});
assert.doesNotThrow(function() {

assert.doesNotThrow(() => {
fs.createWriteStream(example, {encoding: 'utf8'});
});

assert.throws(function() {
assert.throws(() => {
fs.createWriteStream(example, 123);
}, /"options" must be a string or an object/);
assert.throws(function() {
}, numberError);

assert.throws(() => {
fs.createWriteStream(example, 0);
}, /"options" must be a string or an object/);
assert.throws(function() {
}, numberError);

assert.throws(() => {
fs.createWriteStream(example, true);
}, /"options" must be a string or an object/);
assert.throws(function() {
}, booleanError);

assert.throws(() => {
fs.createWriteStream(example, false);
}, /"options" must be a string or an object/);
}, booleanError);

0 comments on commit 1699a8a

Please sign in to comment.