File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -155,14 +155,24 @@ describe('#distribution test (titanium)', function () {
155155 pubnub . reconnect ( ) ;
156156
157157 var finished = false ;
158+ var sawConnected = false ;
158159
159160 pubnub . addListener ( {
160161 status : function ( st ) {
161162 try {
162- expect ( st . operation ) . to . be . equal ( 'PNUnsubscribeOperation' ) ;
163-
163+ // Reconnect finishes asynchronously: first status is often PNSubscribeOperation (connected).
164+ // Wait until connected, then unsubscribe, then assert on the leave request (PNUnsubscribeOperation).
165+ if ( ! sawConnected ) {
166+ if ( st . category === PubNub . CATEGORIES . PNConnectedCategory ) {
167+ sawConnected = true ;
168+ pubnub . unsubscribe ( { channels : [ myChannel1 ] } ) ;
169+ }
170+ return ;
171+ }
172+ if ( st . operation !== 'PNUnsubscribeOperation' ) {
173+ return ;
174+ }
164175 if ( ! finished ) {
165- // prevent calling done twice
166176 finished = true ;
167177 done ( ) ;
168178 }
@@ -171,6 +181,5 @@ describe('#distribution test (titanium)', function () {
171181 }
172182 } ,
173183 } ) ;
174- pubnub . unsubscribe ( { channels : [ myChannel1 ] } ) ;
175184 } ) ;
176185} ) ;
You can’t perform that action at this time.
0 commit comments