summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-write-stream-throw-type-error.js
blob: 5652e9e5e697ccdf3dbea630a817e1d102792aca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');

const numberError =
  /^TypeError: "options" must be a string or an object, got number instead\.$/;

const booleanError =
  /^TypeError: "options" must be a string or an object, got boolean instead\.$/;

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

common.refreshTmpDir();

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

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

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

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

assert.throws(() => {
  fs.createWriteStream(example, 123);
}, numberError);

assert.throws(() => {
  fs.createWriteStream(example, 0);
}, numberError);

assert.throws(() => {
  fs.createWriteStream(example, true);
}, booleanError);

assert.throws(() => {
  fs.createWriteStream(example, false);
}, booleanError);