Skip to content

Commit acefe8f

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
titanium test update to handle async reconnect operation
1 parent 6cced93 commit acefe8f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/dist/web-titanium.test.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)