1
+ /**
2
+ * sse.js - A flexible EventSource polyfill/replacement.
3
+ * https://github.com/mpetazzoni/sse.js
4
+ *
5
+ * Copyright (C) 2016-2024 Maxime Petazzoni <[email protected] >.
6
+ * All rights reserved.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
1
21
import { SSE } from 'sse.js' ;
2
22
3
23
// Setup Mocking for XMLHttpRequest
@@ -32,7 +52,7 @@ beforeEach(() => {
32
52
33
53
34
54
describe ( 'SSE Initialization' , ( ) => {
35
-
55
+
36
56
it ( 'should initialize with default options' , ( ) => {
37
57
const sse = new SSE ( 'http://example.com' ) ;
38
58
expect ( sse . method ) . toBe ( 'GET' ) ;
@@ -164,7 +184,7 @@ describe('SSE Event handling and Listeners', () => {
164
184
expect ( listener . mock . calls [ 0 ] [ 0 ] . event ) . toBe ( undefined ) ;
165
185
expect ( listener . mock . calls [ 0 ] [ 0 ] . id ) . toBe ( '1' ) ;
166
186
expect ( listener . mock . calls [ 0 ] [ 0 ] . lastEventId ) . toBe ( '1' ) ;
167
- } )
187
+ } )
168
188
169
189
it ( 'should handle multiple data events' , ( ) => {
170
190
sse . xhr . responseText = 'id: id1\ndata: First message\n\n' ;
@@ -237,7 +257,7 @@ describe('SSE Event handling and Listeners', () => {
237
257
expect ( listener . mock . calls [ 0 ] [ 0 ] . data ) . toBe ( 'Test message\nmore message' ) ;
238
258
expect ( listener . mock . calls [ 0 ] [ 0 ] . event ) . toBe ( undefined ) ;
239
259
expect ( listener . mock . calls [ 0 ] [ 0 ] . id ) . toBe ( null ) ;
240
- } )
260
+ } )
241
261
242
262
it ( 'should handle an event with a custom event type' , ( ) => {
243
263
sse . xhr . responseText = 'event: customEvent\ndata: Custom event data\n\n' ;
@@ -250,7 +270,7 @@ describe('SSE Event handling and Listeners', () => {
250
270
expect ( customListener . mock . calls [ 0 ] [ 0 ] . type ) . toBe ( 'customEvent' ) ;
251
271
expect ( customListener . mock . calls [ 0 ] [ 0 ] . id ) . toBe ( null ) ;
252
272
} ) ;
253
-
273
+
254
274
it ( 'should handle events different field orders' , ( ) => {
255
275
sse . xhr . responseText = 'data: Custom event data\nevent: customEvent\nid: 1\n\n' ;
256
276
sse . xhr . trigger ( 'progress' , { } ) ;
0 commit comments