• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5const stream = require('stream');
6
7class MyWritable extends stream.Writable {
8  constructor(options) {
9    super({ autoDestroy: false, ...options });
10  }
11  _write(chunk, encoding, callback) {
12    assert.notStrictEqual(chunk, null);
13    callback();
14  }
15}
16
17{
18  const m = new MyWritable({ objectMode: true });
19  m.on('error', common.mustNotCall());
20  assert.throws(() => {
21    m.write(null);
22  }, {
23    code: 'ERR_STREAM_NULL_VALUES'
24  });
25}
26
27{
28  const m = new MyWritable();
29  m.on('error', common.mustNotCall());
30  assert.throws(() => {
31    m.write(false);
32  }, {
33    code: 'ERR_INVALID_ARG_TYPE'
34  });
35}
36
37{ // Should not throw.
38  const m = new MyWritable({ objectMode: true });
39  m.write(false, assert.ifError);
40}
41
42{ // Should not throw.
43  const m = new MyWritable({ objectMode: true }).on('error', (e) => {
44    assert.ifError(e || new Error('should not get here'));
45  });
46  m.write(false, assert.ifError);
47}
48