Skip to content
Browse files

#97 - simplify tests

  • Loading branch information...
1 parent b1d3b55 commit 78160f85492a59f3045060b354884818cbc4e2e8 @majek majek committed
Showing with 24 additions and 16 deletions.
  1. +3 −16 tests/html/src/tests.coffee
  2. +21 −0 tests/html/src/unittests.coffee
View
19 tests/html/src/tests.coffee
@@ -8,26 +8,18 @@ protocols = ['websocket',
'iframe-xhr-polling',
'jsonp-polling']
-url_and_options = (path, protocol) ->
+newSockJS = (path, protocol) ->
url = if /^http/.test(path) then path else client_opts.url + path
options = jQuery.extend({}, client_opts.sockjs_opts)
if protocol
options.protocols_whitelist = [protocol]
- [url, options]
-
-newSockJS = (path, protocol) ->
- [url, options] = url_and_options(path, protocol)
return new SockJS(url, null, options)
-cons_without_new = (path, protocol) ->
- [url, options] = url_and_options(path, protocol)
- return SockJS(url, null, options)
-
-echo_factory_factory = (protocol, messages, cons = newSockJS) ->
+echo_factory_factory = (protocol, messages) ->
return ->
expect(2 + messages.length)
a = messages.slice(0)
- r = cons('/echo', protocol)
+ r = newSockJS('/echo', protocol)
r.onopen = (e) ->
#log('onopen ' + e)
ok(true)
@@ -55,10 +47,6 @@ echo_factory_factory = (protocol, messages, cons = newSockJS) ->
ok(true)
start()
-factor_echo_without_new = (protocol) ->
- messages = [ 'data' ]
- return echo_factory_factory(protocol, messages, cons_without_new)
-
factor_echo_basic = (protocol) ->
messages = [ 'data' ]
return echo_factory_factory(protocol, messages)
@@ -302,7 +290,6 @@ test_protocol_messages = (protocol) ->
test "[disabled by config]", ->
log('Disabled by config: "' + protocol + '"')
else
- asyncTest("echo0", factor_echo_without_new(protocol))
asyncTest("echo1", factor_echo_basic(protocol))
asyncTest("echo2", factor_echo_rich(protocol))
asyncTest("unicode", factor_echo_unicode(protocol))
View
21 tests/html/src/unittests.coffee
@@ -237,3 +237,24 @@ test "EventEmitter", ->
r.removeEventListener 'close', single
r.dispatchEvent({type:'close'}) # 0 runs
r.close()
+
+
+instanceof_working = false
+try
+ obj = {}
+ instanceof_working = obj instanceof Object
+catch x
+ #pass
+
+if not instanceof_working
+ test "[NoConstructor unsupported by client]", ->
+ log('NoConstructor unsupported by client')
+else
+ test "NoConstructor", ->
+ expect(2)
+ r = new SockJS('//1.2.3.4/blah', null, {protocols_whitelist: []})
+ ok(r instanceof SockJS)
+ r.close()
+ r = SockJS('//1.2.3.4/blah', null, {protocols_whitelist: []})
+ ok(r instanceof SockJS)
+ r.close()

0 comments on commit 78160f8

Please sign in to comment.
Something went wrong with that request. Please try again.