Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added websocket tests

  • Loading branch information...
commit 1d1acd3ddd09d3debd946eacde4de59b152de9ba 1 parent e306ae0
Animesh Kumar authored filmaj committed
Showing with 62 additions and 0 deletions.
  1. +62 −0 tests/websocket.tests.js
View
62 tests/websocket.tests.js
@@ -0,0 +1,62 @@
+Tests.prototype.WebSocketTests = function() {
+ module('WebSocket model');
+ test("should be able to define a WebSocket object", function() {
+ expect(1);
+ try {
+ var websocket = new WebSocket('ws://localhost/');
+ ok(websocket != null, "new WebSocket('valid-url') should not be null.");
+ websocket.close();
+ } catch (e) {
+ }
+ });
+ test("should throw errors if 'url is invalid'", function() {
+ expect(1);
+ try {
+ var websocket = new WebSocket('--invalid--');
+ } catch (e) {
+ ok(e != null, "new WebSocket('valid-url') should throw error.");
+ }
+ });
+ test("should contain a 'send' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.send != 'undefined' && websocket.send != null, "websocket.send should not be null.");
+ ok(typeof websocket.send == 'function', "websocket.send should be a function.");
+ websocket.close();
+ });
+ test("should contain a 'close' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.close != 'undefined' && websocket.close != null, "websocket.close should not be null.");
+ ok(typeof websocket.close == 'function', "websocket.close should be a function.");
+ websocket.close();
+ });
+ test("should contain a 'onopen' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.onopen != 'undefined' && websocket.onopen != null, "websocket.onopen should not be null.");
+ ok(typeof websocket.onopen == 'function', "websocket.onopen should be a function.");
+ websocket.close();
+ });
+ test("should contain a 'onclose' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.onclose != 'undefined' && websocket.onclose != null, "websocket.onclose should not be null.");
+ ok(typeof websocket.onclose == 'function', "websocket.onclose should be a function.");
+ websocket.close();
+ });
+ test("should contain a 'onerror' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.onerror != 'undefined' && websocket.onerror != null, "websocket.onerror should not be null.");
+ ok(typeof websocket.onerror == 'function', "websocket.onerror should be a function.");
+ websocket.close();
+ });
+ test("should contain a 'onmessage' function", function() {
+ expect(2);
+ var websocket = new WebSocket('ws://localhost/');
+ ok(typeof websocket.onmessage != 'undefined' && websocket.onmessage != null, "websocket.onmessage should not be null.");
+ ok(typeof websocket.onmessage == 'function', "websocket.onmessage should be a function.");
+ websocket.close();
+ });
+};
Please sign in to comment.
Something went wrong with that request. Please try again.