Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve test-fs-write-stream-throw-type #10779

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: improve test-fs-write-stream-throw-type
* validate the errors for all assert.throws
* use arrow functions
  • Loading branch information
edsadr committed Jan 13, 2017
commit 7856c7372f5addd49ed2d6ddda950ddfae01f659
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);