mirror of
https://github.com/nodejs/node.git
synced 2025-05-18 20:40:20 +00:00

The assert.fail function signature has the message as the third argument but, understandably, it is often assumed that it is the first argument (or at least the first argument if no other arguments are passed). This corrects the assert.fail() invocations in the Node.js tests. Before: assert.fail('message'); // result: AssertionError: 'message' undefined undefined After: assert.fail(null, null, 'message'); // result: AssertionError: message PR-URL: https://github.com/nodejs/node/pull/3378 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
38 lines
1001 B
JavaScript
38 lines
1001 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var mustCall = common.mustCall;
|
|
var assert = require('assert');
|
|
var dgram = require('dgram');
|
|
var dns = require('dns');
|
|
|
|
var socket = dgram.createSocket('udp4');
|
|
var buffer = new Buffer('gary busey');
|
|
|
|
dns.setServers([]);
|
|
|
|
socket.once('error', onEvent);
|
|
|
|
// assert that:
|
|
// * callbacks act as "error" listeners if given.
|
|
// * error is never emitter for missing dns entries
|
|
// if a callback that handles error is present
|
|
// * error is emitted if a callback with no argument is passed
|
|
socket.send(buffer, 0, buffer.length, 100,
|
|
'dne.example.com', mustCall(callbackOnly));
|
|
|
|
function callbackOnly(err) {
|
|
assert.ok(err);
|
|
socket.removeListener('error', onEvent);
|
|
socket.on('error', mustCall(onError));
|
|
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com');
|
|
}
|
|
|
|
function onEvent(err) {
|
|
assert.fail(null, null, 'Error should not be emitted if there is callback');
|
|
}
|
|
|
|
function onError(err) {
|
|
assert.ok(err);
|
|
socket.close();
|
|
}
|