@@ -308,6 +308,24 @@ describe('RedisPubSub', () => {
308
308
}
309
309
} ) ;
310
310
311
+ it ( 'custom serializer can throw an error' , done => {
312
+ const serializer = stub ( ) ;
313
+ serializer . throwWith ( new Error ( 'Custom serialization error' ) ) ;
314
+
315
+ const pubSub = new RedisPubSub ( { ...mockOptions , serializer } ) ;
316
+
317
+ try {
318
+ pubSub . publish ( 'TOPIC' , { hello : 'world' } ) . then ( ( ) => {
319
+ done ( new Error ( 'Expected error to be thrown upon publish' ) ) ;
320
+ } , err => {
321
+ expect ( err . message ) . to . eql ( 'Custom serialization error' ) ;
322
+ done ( ) ;
323
+ } )
324
+ } catch ( e ) {
325
+ done ( e ) ;
326
+ }
327
+ } ) ;
328
+
311
329
it ( 'allows to use a custom deserializer' , done => {
312
330
const deserializer = stub ( ) ;
313
331
const deserializedPayload = { hello : 'custom' } ;
@@ -331,6 +349,29 @@ describe('RedisPubSub', () => {
331
349
}
332
350
} ) ;
333
351
352
+ it ( 'unparsed payload is returned if custom deserializer throws an error' , done => {
353
+ const deserializer = stub ( ) ;
354
+ deserializer . throwWith ( new Error ( 'Custom deserialization error' ) ) ;
355
+
356
+ const pubSub = new RedisPubSub ( { ...mockOptions , deserializer } ) ;
357
+
358
+ try {
359
+ pubSub . subscribe ( 'TOPIC' , message => {
360
+ try {
361
+ expect ( message ) . to . be . a ( 'string' ) ;
362
+ expect ( message ) . to . eql ( '{"hello":"world"}' ) ;
363
+ done ( ) ;
364
+ } catch ( e ) {
365
+ done ( e ) ;
366
+ }
367
+ } ) . then ( ( ) => {
368
+ pubSub . publish ( 'TOPIC' , { hello : 'world' } ) ;
369
+ } ) ;
370
+ } catch ( e ) {
371
+ done ( e ) ;
372
+ }
373
+ } ) ;
374
+
334
375
it ( 'throws if you try to unsubscribe with an unknown id' , ( ) => {
335
376
const pubSub = new RedisPubSub ( mockOptions ) ;
336
377
return expect ( ( ) => pubSub . unsubscribe ( 123 ) )
0 commit comments