@@ -41,6 +41,15 @@ describe("watch - websockets", () => {
41
41
assertEquals ( value . type , "message" ) ;
42
42
assertEquals ( value . data , "test" ) ;
43
43
} ) ;
44
+
45
+ it ( "should remove the event listener when the stream is canceled" , async ( ) => {
46
+ const stream = watch ( ws ) ( "message" ) ;
47
+ const reader = stream . getReader ( ) ;
48
+ reader . cancel ( ) ;
49
+ ws . dispatchEvent ( new MessageEvent ( "message" , { data : "test" } ) ) ;
50
+ const { done } = await reader . read ( ) ;
51
+ assertEquals ( done , true ) ;
52
+ } ) ;
44
53
} ) ;
45
54
46
55
describe ( "watch - relays" , ( ) => {
@@ -85,4 +94,13 @@ describe("watch - relays", () => {
85
94
assertEquals ( value . type , "receive" ) ;
86
95
assertEquals ( value . data , [ "NOTICE" , "test" ] ) ;
87
96
} ) ;
97
+
98
+ it ( "should remove the event listener when the stream is canceled" , async ( ) => {
99
+ const stream = watch ( relay ) ( "receive" ) ;
100
+ const reader = stream . getReader ( ) ;
101
+ reader . cancel ( ) ;
102
+ relay . dispatch ( "receive" , [ "NOTICE" , "test" ] ) ;
103
+ const { done } = await reader . read ( ) ;
104
+ assertEquals ( done , true ) ;
105
+ } ) ;
88
106
} ) ;
0 commit comments