0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stream-writable-null.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

57 lines
1.3 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const stream = require('stream');
const util = require('util');
function MyWritable(options) {
stream.Writable.call(this, options);
}
util.inherits(MyWritable, stream.Writable);
MyWritable.prototype._write = function(chunk, encoding, callback) {
assert.notStrictEqual(chunk, null);
callback();
};
assert.throws(() => {
const m = new MyWritable({objectMode: true});
m.write(null, (err) => assert.ok(err));
}, TypeError, 'May not write null values to stream');
assert.doesNotThrow(() => {
const m = new MyWritable({objectMode: true}).on('error', (e) => {
assert.ok(e);
});
m.write(null, (err) => {
assert.ok(err);
});
});
assert.throws(() => {
const m = new MyWritable();
m.write(false, (err) => assert.ok(err));
}, TypeError, 'Invalid non-string/buffer chunk');
assert.doesNotThrow(() => {
const m = new MyWritable().on('error', (e) => {
assert.ok(e);
});
m.write(false, (err) => {
assert.ok(err);
});
});
assert.doesNotThrow(() => {
const m = new MyWritable({objectMode: true});
m.write(false, (err) => assert.ifError(err));
});
assert.doesNotThrow(() => {
const m = new MyWritable({objectMode: true}).on('error', (e) => {
assert.ifError(e || new Error('should not get here'));
});
m.write(false, (err) => {
assert.ifError(err);
});
});