Skip to content

Commit 2e70bcc

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
refactor test to consider reconnect() async behaviour
1 parent acefe8f commit 2e70bcc

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

test/dist/web-titanium.test.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,17 @@ describe('#distribution test (titanium)', function () {
155155
pubnub.reconnect();
156156

157157
var finished = false;
158-
var sawConnected = false;
159158

160159
pubnub.addListener({
161160
status: function (st) {
162161
try {
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') {
162+
if(st.category === 'PNConnectedCategory') {
163+
// this is expected due to async nature of the reconnect()
173164
return;
174165
}
166+
expect(st.category).to.be.equal('PNDisconnectedCategory');
175167
if (!finished) {
168+
// prevent calling done twice
176169
finished = true;
177170
done();
178171
}
@@ -181,5 +174,6 @@ describe('#distribution test (titanium)', function () {
181174
}
182175
},
183176
});
177+
pubnub.unsubscribe({ channels: [myChannel1] });
184178
});
185179
});

0 commit comments

Comments
 (0)