@@ -27,6 +27,7 @@ if (!common.hasCrypto)
2727const assert = require ( 'assert' ) ;
2828const tls = require ( 'tls' ) ;
2929const fixtures = require ( '../common/fixtures' ) ;
30+ const { mock } = require ( 'node:test' ) ;
3031
3132const 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