[Pkg-javascript-commits] [sockjs-client] 189/350: Tests from issues
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:04:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit 23f657b8252ed13bbd1527322366d397e8108145
Author: Bryce Kahle <bkahle at gmail.com>
Date: Mon Oct 20 00:41:33 2014 -0400
Tests from issues
---
lib/event/eventtarget.js | 2 +-
lib/main.js | 9 ++++++---
tests/lib/main.js | 16 ++++++++++++++++
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/lib/event/eventtarget.js b/lib/event/eventtarget.js
index 44a37fe..a09ce92 100644
--- a/lib/event/eventtarget.js
+++ b/lib/event/eventtarget.js
@@ -13,7 +13,7 @@ EventTarget.prototype.addEventListener = function (eventType, listener) {
this._listeners[eventType] = [];
}
var arr = this._listeners[eventType];
- // sockjs/sockjs-client#4
+ // #4
if (arr.indexOf(listener) === -1) {
// Make a copy so as not to interfere with a current dispatchEvent.
arr = arr.concat([listener]);
diff --git a/lib/main.js b/lib/main.js
index c51d552..cdd68e9 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -36,6 +36,9 @@ function SockJS(url, protocols, transportsWhitelist) {
if (!(this instanceof SockJS)) {
return new SockJS(url, protocols);
}
+ if (arguments.length < 1) {
+ throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
+ }
EventTarget.call(this);
this.readyState = SockJS.CONNECTING;
@@ -48,7 +51,7 @@ function SockJS(url, protocols, transportsWhitelist) {
// TODO specify via options? server routes require this
this._server = random.numberString(1000);
- // Step 1 of WS spec - parse and validate the url
+ // Step 1 of WS spec - parse and validate the url. Issue #8
var parsedUrl = u.parse(url);
if (!parsedUrl.host || !parsedUrl.pathname || !parsedUrl.protocol) {
throw new SyntaxError("The URL '" + url + "' is invalid");
@@ -142,10 +145,10 @@ SockJS.prototype.close = function(code, reason) {
};
SockJS.prototype.send = function(data) {
- // TODO seems we should uphold WS spec and not allow anything but strings
+ // #13 - convert anything non-string to string
+ // TODO this currently turns objects into [object Object]
if (typeof data !== 'string') {
data = '' + data;
- //throw new TypeError('data must be a string');
}
if (this.readyState === SockJS.CONNECTING) {
throw new InvalidStateError('The connection has not been established yet');
diff --git a/tests/lib/main.js b/tests/lib/main.js
index 169e63b..5302b68 100644
--- a/tests/lib/main.js
+++ b/tests/lib/main.js
@@ -36,6 +36,22 @@ describe('SockJS', function() {
});
});
+ it('should throw SyntaxError for an empty url - #8', function () {
+ expect(function () {
+ new SockJS('');
+ }).to.throwException(function (e) {
+ expect(e).to.be.a(SyntaxError);
+ });
+ });
+
+ it('should throw TypeError for an null url', function () {
+ expect(function () {
+ new SockJS();
+ }).to.throwException(function (e) {
+ expect(e).to.be.a(TypeError);
+ });
+ });
+
it('should throw SyntaxError when the url contains a querystring or fragment', function () {
expect(function () {
new SockJS('http://localhost/?test');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list