Skip to content

Commit

Permalink
fixup: test
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Feb 17, 2020
1 parent 10283bb commit 93c4107
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
11 changes: 5 additions & 6 deletions test/parallel/test-fs-write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ tmpdir.refresh();
// Throws if data is not of type Buffer.
{
const stream = fs.createWriteStream(file);
stream.on('error', common.expectsError({
stream.on('error', common.mustNotCall());
assert.throws(() => {
stream.write(42);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}));
stream.write(42, null, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}));
});
stream.destroy();
}
12 changes: 6 additions & 6 deletions test/parallel/test-net-socket-write-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

const common = require('../common');
const net = require('net');
const assert = require('assert');

const server = net.createServer().listen(0, connectToServer);

function connectToServer() {
const client = net.createConnection(this.address().port, () => {
client.write(1337, common.expectsError({
client.on('error', common.mustNotCall());
assert.throws(() => {
client.write(1337);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}));
client.on('error', common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}));
});

client.destroy();
})
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-net-write-arguments.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
'use strict';
const common = require('../common');
const net = require('net');

const assert = require('assert');
const socket = net.Stream({ highWaterMark: 0 });

// Make sure that anything besides a buffer or a string throws.
socket.write(null, common.expectsError({
socket.on('error', common.mustNotCall());
assert.throws(() => {
socket.write(null);
}, {
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError',
message: 'May not write null values to stream'
}));
socket.on('error', common.expectsError({
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError',
message: 'May not write null values to stream'
}));
});

[
true,
Expand All @@ -29,10 +27,12 @@ socket.on('error', common.expectsError({
].forEach((value) => {
// We need to check the callback since 'error' will only
// be emitted once per instance.
socket.write(value, common.expectsError({
assert.throws(() => {
socket.write(value);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "chunk" argument must be of type string or an instance of ' +
`Buffer or Uint8Array.${common.invalidArgTypeHelper(value)}`
}));
});
});
12 changes: 6 additions & 6 deletions test/parallel/test-stream2-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,12 @@ const helloWorldBuffer = Buffer.from('hello world');
{
// Verify that error is only emitted once when failing in write.
const w = new W();
w.on('error', common.mustCall((err) => {
assert.strictEqual(w._writableState.errorEmitted, true);
assert.strictEqual(err.code, 'ERR_STREAM_NULL_VALUES');
}));
w.write(null);
w.destroy(new Error());
w.on('error', common.mustNotCall());
assert.throws(() => {
w.write(null);
}, {
code: 'ERR_STREAM_NULL_VALUES'
});
}

{
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-zlib-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const unzips = [
];

nonStringInputs.forEach(common.mustCall((input) => {
// zlib.gunzip should not throw an error when called with bad input.
zlib.gunzip(input, (err, buffer) => {
// zlib.gunzip should pass the error to the callback.
assert.ok(err);
assert.throws(() => {
zlib.gunzip(input);
}, {
name: 'TypeError'
});
}, nonStringInputs.length));

Expand Down
11 changes: 6 additions & 5 deletions test/parallel/test-zlib-object-write.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { Gunzip } = require('zlib');

const gunzip = new Gunzip({ objectMode: true });
gunzip.write({}, common.expectsError({
gunzip.on('error', common.mustNotCall());
assert.throws(() => {
gunzip.write({});
}, {
name: 'TypeError'
}));
gunzip.on('error', common.expectsError({
name: 'TypeError'
}));
});

0 comments on commit 93c4107

Please sign in to comment.