@@ -4,16 +4,19 @@ import xml from "@xmpp/xml";
44import ConnectionWebSocket from "../lib/Connection.js" ;
55import Socket from "../lib/Socket.js" ;
66
7- test ( "send()" , ( ) => {
7+ test ( "send()" , async ( ) => {
88 const connection = new ConnectionWebSocket ( ) ;
9- connection . write = ( ) => { } ;
9+ connection . socket = new Socket ( ) ;
10+ connection . socket . socket = {
11+ send : jest . fn ( ) ,
12+ } ;
1013 connection . root = xml ( "root" ) ;
1114
1215 const element = xml ( "presence" ) ;
1316
1417 expect ( element . attrs . xmlns ) . toBe ( undefined ) ;
1518 expect ( element . parent ) . toBe ( null ) ;
16- connection . send ( element ) ;
19+ await connection . send ( element ) ;
1720 expect ( element . attrs . xmlns ) . toBe ( "jabber:client" ) ;
1821 expect ( element . parent ) . toBe ( connection . root ) ;
1922} ) ;
@@ -70,6 +73,9 @@ test("socket close", () => {
7073test ( "sendMany" , async ( ) => {
7174 const conn = new ConnectionWebSocket ( ) ;
7275 conn . socket = new Socket ( ) ;
76+ conn . socket . socket = {
77+ send : jest . fn ( ) ,
78+ } ;
7379 const spy_write = jest . spyOn ( conn . socket , "write" ) ;
7480 conn . root = xml ( "root" ) ;
7581
@@ -82,7 +88,7 @@ test("sendMany", async () => {
8288 expect ( element . parent ) . toBe ( null ) ;
8389 }
8490
85- conn . sendMany ( elements ) ;
91+ await conn . sendMany ( elements ) ;
8692
8793 for ( const element of elements ) {
8894 expect ( element . attrs . xmlns ) . toBe ( "jabber:client" ) ;
0 commit comments