* [html5] update webSocket unit test

Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/1bbe8866
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1bbe8866
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1bbe8866

Branch: refs/heads/0.15-dev
Commit: 1bbe8866fc537f39368ae04b241fbbaf2a4e24a6
Parents: b978273
Author: erha19 <[email protected]>
Authored: Thu Jul 13 13:16:49 2017 +0800
Committer: erha19 <[email protected]>
Committed: Thu Jul 13 13:16:49 2017 +0800

----------------------------------------------------------------------
 html5/test/render/vue/modules/websocket.js | 72 +++++++++++++------------
 1 file changed, 39 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1bbe8866/html5/test/render/vue/modules/websocket.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/modules/websocket.js 
b/html5/test/render/vue/modules/websocket.js
index 487334a..3b34c51 100644
--- a/html5/test/render/vue/modules/websocket.js
+++ b/html5/test/render/vue/modules/websocket.js
@@ -19,63 +19,69 @@
 import websocket from '../../../../render/vue/modules/websocket/websocket'
 const TestUrl = 'ws://echo.websocket.org'
 /** @test {webSocket module} */
-describe('webSocket module', function () {
-  describe('extends Standard WebSocket API', function () {
-    context('should inherit', function () {
-      const ws = websocket.WebSocket(TestUrl)
-      it('methods', function () {
+describe('webSocket module', () => {
+
+  describe('extends Standard WebSocket API', () => {
+    context('should inherit', () => {
+      let ws = null
+      before(() => {
+        ws = websocket.WebSocket(TestUrl)
+      })
+      after(() => {
+        websocket.close()
+      })
+      it('methods', () => {
         expect(websocket, 'should close method to be 
defined').to.have.property('close')
         expect(websocket, 'should send method to be 
defined').to.have.property('send')
       })
-      it('attributes', function () {
+      it('attributes', () => {
         expect(websocket, 'should onerror to be 
defined').to.have.property('onerror')
         expect(websocket, 'should onmessage to be 
defined').to.have.property('onmessage')
         expect(websocket, 'should onopen to be 
defined').to.have.property('onopen')
         expect(websocket, 'should onclose to be 
defined').to.have.property('onclose')
         expect(ws, 'should binaryType to be 
defined').to.have.property('binaryType')
-        expect(ws, 'should bufferdAmount to be 
defined').to.have.property('bufferedAmount')
-        expect(ws, 'should extensions to be 
defined').to.have.property('extensions')
         expect(ws, 'should protocol to be 
defined').to.have.property('protocol')
         expect(ws, 'should readyState to be 
defined').to.have.property('readyState')
         expect(ws, 'should url to be defined').to.have.property('url')
       })
-      it('constants', function () {
+      it('constants', () => {
         expect(websocket, 'should INSTANCE to be 
defined').to.have.property('INSTANCE')
       })
     })
-    context('should forward native events', function () {
+    context('should forward native events', () => {
       let ws = null
-      beforeEach(function () {
-        ws = websocket.WebSocket(TestUrl, '')
+      before(() => {
+        ws = websocket.WebSocket(TestUrl,'')
       })
-      afterEach(function () {
+      after(() => {
         websocket.close()
       })
-      it('open && message && close', function (done) {
-        let closed = false
-        const message = 'Test'
-        ws.onclose = function () {
-          if (!closed) {
-            closed = true
-          }
-          expect(closed).to.be.true
-          done()
+      it('open', function () {
+        const open  = () => {
         }
-        websocket.onmessage = function (e) {
-          expect(e.data).to.be.equal(message)
-          setTimeout(() => { websocket.close() }, 200)
+        websocket.onopen = open
+        expect(ws.onopen).to.be.deep.equal(open)
+      })
+      it('close', function () {
+        const close  = () => {
         }
-        websocket.onopen = function () {
-          websocket.send(message)
+        websocket.onclose = close
+        expect(ws.onclose).to.be.deep.equal(close)
+      })
+      it('error', function () {
+        const error  = () => {
         }
+        websocket.onerror = error
+        expect(ws.onerror).to.be.deep.equal(error)
       })
-    })
-    describe('should ignore', function () {
-      it('protocol is undefined', function (done) {
-        websocket.WebSocket(TestUrl)
-        expect(websocket.INSTANCE).not.to.be.null
-        done()
+      it('message', function () {
+        const message  = () => {
+        }
+        websocket.onmessage = message
+        expect(ws.onmessage).to.be.deep.equal(message)
       })
+    })
+    describe('should ignore', () => {
       it('url is undefined', function (done) {
         websocket.WebSocket('')
         expect(websocket.INSTANCE).to.be.null

Reply via email to