Skip to content

Commit 636493c

Browse files
committed
test: improve test-tls-set-encoding.js
1 parent 795dd8e commit 636493c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

test/parallel/test-tls-set-encoding.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if (!common.hasCrypto)
2727
const assert = require('assert');
2828
const tls = require('tls');
2929
const fixtures = require('../common/fixtures');
30+
const { mock } = require('node:test');
3031

3132
const options = {
3233
key: fixtures.readKey('agent2-key.pem'),
@@ -57,13 +58,12 @@ server.listen(0, function() {
5758

5859
client.on('data', function(d) {
5960
console.log('client: on data', d);
60-
assert.ok(typeof d === 'string');
61+
assert.strictEqual(typeof d, 'string');
6162
buffer += d;
6263
});
6364

64-
client.on('secureConnect', common.mustCall(() => {
65-
console.log('client: on secureConnect');
66-
}));
65+
const secureConnectFn = mock.fn();
66+
client.on('secureConnect', secureConnectFn);
6767

6868
client.on('close', common.mustCall(function() {
6969
console.log('client: on close');
@@ -81,6 +81,9 @@ server.listen(0, function() {
8181
// and thus does equal the ASCII string representation
8282
assert.strictEqual(messageAscii, buffer);
8383

84+
// Ensure that secureConnect is only emitted once.
85+
assert.strictEqual(secureConnectFn.mock.callCount(), 1);
86+
8487
server.close();
8588
}));
8689
});

0 commit comments

Comments
 (0)