0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-dgram-setBroadcast.js
cjihrig fe2b5f0dd2 test: refactor test-dgram-setBroadcast.js
This test wasn't actually working, as sockets were being closed,
allowing the test to exit before any assertions were actually
run. This commit refactors the test to maintain the same intended
semantics.

PR-URL: https://github.com/nodejs/node/pull/11252
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-02-11 10:05:32 -08:00

26 lines
552 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
{
// Should throw EBADF if the socket is never bound.
const socket = dgram.createSocket('udp4');
assert.throws(() => {
socket.setBroadcast(true);
}, /^Error: setBroadcast EBADF$/);
}
{
// Can call setBroadcast() after binding the socket.
const socket = dgram.createSocket('udp4');
socket.bind(0, common.mustCall(() => {
socket.setBroadcast(true);
socket.setBroadcast(false);
socket.close();
}));
}