Created
September 1, 2015 20:50
-
-
Save gisfromscratch/4f8141d8a72fe63e6f6b to your computer and use it in GitHub Desktop.
Strophe.js unit test for connecting to a XMPP Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Chat TestSuite</title> | |
<script src="/lib/strophe.min.js"></script> | |
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.19.0.css"> | |
<script src="//code.jquery.com/qunit/qunit-1.19.0.js"></script> | |
<script type="text/javascript"> | |
QUnit.config.autostart = false; | |
// Testing prepare | |
var xmppServerUrl = "https://<XMPP_SERVER>:7071/http-bind/"; | |
var xmppLoginName = "<XMPP_LOGIN>"; | |
var xmppPassword = "<XMPP_PASS>"; | |
var jid = "<XMPP_LOGIN>@<XMPP_SERVER>/TestBot"; | |
QUnit.test("connect async test: async connect", function (assert) { | |
function toStateMessage(status) { | |
switch (status) { | |
case Strophe.Status.CONNECTING: | |
return "Connecting"; | |
case Strophe.Status.CONNECTED: | |
return "Connected"; | |
default: | |
return "Status code=" + status; | |
} | |
} | |
var triggerContinuation = assert.async(); | |
var isConnected = false; | |
var connection = new Strophe.Connection(xmppServerUrl, { sync: false }); | |
connection.connect(jid, xmppPassword, function (status) { | |
if (!isConnected) { | |
switch (status) { | |
case Strophe.Status.CONNECTED: | |
isConnected = true; | |
break; | |
} | |
} | |
console.debug(toStateMessage(status)); | |
}); | |
var waitDurationInMsec = 3000; | |
setTimeout(function () { | |
assert.ok(isConnected, "Assert connection state"); | |
triggerContinuation(); | |
}, waitDurationInMsec); | |
}); | |
QUnit.start(); | |
</script> | |
</head> | |
<body> | |
<div id="qunit"></div> | |
<div id="qunit-fixture"></div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment