@@ -139,6 +139,7 @@ async function createSubscription(
139
139
async function expectPromiseToThrow ( promise , message ) {
140
140
try {
141
141
await promise ( ) ;
142
+ /* istanbul ignore next */
142
143
expect . fail ( 'promise should have thrown but did not' ) ;
143
144
} catch ( error ) {
144
145
expect ( error && error . message ) . to . equal ( message ) ;
@@ -280,6 +281,7 @@ describe('Subscription Initialization Phase', () => {
280
281
} ,
281
282
nonImportantEmail : {
282
283
type : EmailEventType ,
284
+ /* istanbul ignore next (shouldn't be called) */
283
285
subscribe ( ) {
284
286
didResolveNonImportantEmail = true ;
285
287
return eventEmitterAsyncIterator ( new EventEmitter ( ) , 'event' ) ;
@@ -516,27 +518,9 @@ describe('Subscription Initialization Phase', () => {
516
518
}
517
519
` ) ;
518
520
519
- const pubsub = new EventEmitter ( ) ;
520
- const rootValue = {
521
- inbox : {
522
- emails : [
523
- {
524
- from : 'joe@graphql.org' ,
525
- subject : 'Hello' ,
526
- message : 'Hello World' ,
527
- unread : false ,
528
- } ,
529
- ] ,
530
- } ,
531
- importantEmail ( ) {
532
- return eventEmitterAsyncIterator ( pubsub , 'importantEmail' ) ;
533
- } ,
534
- } ;
535
-
536
521
const result = await subscribe ( {
537
522
schema : emailSchema ,
538
523
document : ast ,
539
- rootValue,
540
524
variableValues : { priority : 'meow' } ,
541
525
} ) ;
542
526
@@ -806,6 +790,68 @@ describe('Subscription Publish Phase', () => {
806
790
} ) ;
807
791
} ) ;
808
792
793
+ it ( 'should not trigger when subscription is thrown' , async ( ) => {
794
+ const pubsub = new EventEmitter ( ) ;
795
+ const { sendImportantEmail, subscription } = await createSubscription (
796
+ pubsub ,
797
+ ) ;
798
+ let payload = subscription . next ( ) ;
799
+
800
+ // A new email arrives!
801
+ expect (
802
+ sendImportantEmail ( {
803
+ from : 'yuzhi@graphql.org' ,
804
+ subject : 'Alright' ,
805
+ message : 'Tests are good' ,
806
+ unread : true ,
807
+ } ) ,
808
+ ) . to . equal ( true ) ;
809
+
810
+ expect ( await payload ) . to . deep . equal ( {
811
+ done : false ,
812
+ value : {
813
+ data : {
814
+ importantEmail : {
815
+ email : {
816
+ from : 'yuzhi@graphql.org' ,
817
+ subject : 'Alright' ,
818
+ } ,
819
+ inbox : {
820
+ unread : 1 ,
821
+ total : 2 ,
822
+ } ,
823
+ } ,
824
+ } ,
825
+ } ,
826
+ } ) ;
827
+
828
+ payload = subscription . next ( ) ;
829
+
830
+ // Throw error
831
+ let caughtError ;
832
+ try {
833
+ await subscription . throw ( 'ouch' ) ;
834
+ } catch ( e ) {
835
+ caughtError = e ;
836
+ }
837
+ expect ( caughtError ) . to . equal ( 'ouch' ) ;
838
+
839
+ // A new email arrives!
840
+ expect (
841
+ sendImportantEmail ( {
842
+ from : 'yuzhi@graphql.org' ,
843
+ subject : 'Alright 2' ,
844
+ message : 'Tests are good 2' ,
845
+ unread : true ,
846
+ } ) ,
847
+ ) . to . equal ( false ) ;
848
+
849
+ expect ( await payload ) . to . deep . equal ( {
850
+ done : true ,
851
+ value : undefined ,
852
+ } ) ;
853
+ } ) ;
854
+
809
855
it ( 'event order is correct for multiple publishes' , async ( ) => {
810
856
const pubsub = new EventEmitter ( ) ;
811
857
const { sendImportantEmail, subscription } = await createSubscription (
0 commit comments