@@ -171,6 +171,25 @@ describe("client-js", () => {
171
171
} ) ;
172
172
} ) ;
173
173
174
+ it ( "onData throws if the ID is not found" , async ( ) => {
175
+ const emitter = new EventEmitter ( ) ;
176
+ const transport = new EventEmitterTransport ( emitter , "from1" , "to1" ) ;
177
+ const serverTransport = new EventEmitterTransport ( emitter , "to1" , "from1" ) ;
178
+ const c = new RequestManager ( [ transport ] ) ;
179
+ await c . connect ( ) ;
180
+ expect ( ( ) => serverTransport . sendData ( JSON . stringify ( {
181
+ jsonrpc : "2.0" ,
182
+ id : 10 ,
183
+ error : {
184
+ code : 0 ,
185
+ message : "out of order" ,
186
+ data : {
187
+ foo : "bar" ,
188
+ } ,
189
+ } ,
190
+ } ) ) ) . toThrow ( ) ;
191
+ } ) ;
192
+
174
193
describe ( "stopBatch" , ( ) => {
175
194
it ( "does nothing if the batch is empty" , ( ) => {
176
195
const emitter = new EventEmitter ( ) ;
@@ -182,4 +201,19 @@ describe("client-js", () => {
182
201
expect ( transport . sendData ) . not . toHaveBeenCalled ( ) ;
183
202
} ) ;
184
203
} ) ;
204
+
205
+ describe ( "startBatch" , ( ) => {
206
+ it ( "it does nothing if a batch is already started" , async ( ) => {
207
+ const emitter = new EventEmitter ( ) ;
208
+ const transport = new EventEmitterTransport ( emitter , "from1" , "to1" ) ;
209
+ const c = new RequestManager ( [ transport ] ) ;
210
+ await c . connect ( ) ;
211
+ c . startBatch ( ) ;
212
+ c . request ( "foo" , [ ] ) ;
213
+ expect ( c . batch . length ) . toBe ( 1 ) ;
214
+ c . startBatch ( ) ;
215
+ c . request ( "foo" , [ ] ) ;
216
+ expect ( c . batch . length ) . toBe ( 2 ) ;
217
+ } ) ;
218
+ } ) ;
185
219
} ) ;
0 commit comments