Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 4446c5a

Browse files
authored
[CORE-1394] Streamr Client: Type Error (#14)
* Add null checking when modifying the subscription * Remove babel from mocha and fix tests
1 parent ca09a5a commit 4446c5a

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"build": "webpack --env dev && webpack --env prod && npm run test",
1515
"dev": "webpack --progress --colors --watch --env dev",
1616
"test": "npm run test-unit && npm run test-integration",
17-
"test:watch": "mocha --require babel-core/register --colors -w --recursive ./test",
18-
"test-unit": "mocha --require babel-core/register --colors --recursive ./test/unit",
19-
"test-integration": "mocha --require babel-core/register --colors --recursive ./test/integration"
17+
"test:watch": "mocha -w ./test",
18+
"test-unit": "mocha ./test/unit",
19+
"test-integration": "mocha ./test/integration"
2020
},
2121
"browser": {
2222
"ws": "./src/shim/ws.js",

src/StreamrClient.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ module.exports = class StreamrClient extends EventEmitter {
195195
this.handleError(`Error subscribing to ${response.stream}: ${response.error}`)
196196
} else {
197197
const subs = this.subsByStream[response.stream]
198-
delete subs.subscribing
198+
if (subs && typeof subs === 'object') {
199+
delete subs.subscribing
200+
}
199201

200202
debug('Client subscribed: %o', response)
201203

@@ -276,7 +278,9 @@ module.exports = class StreamrClient extends EventEmitter {
276278
Object.keys(this.subsByStream)
277279
.forEach((streamId) => {
278280
const subs = this.subsByStream[streamId]
279-
delete subs.subscribing
281+
if (subs && typeof subs === 'object') {
282+
delete subs.subscribing
283+
}
280284
subs.forEach((sub) => {
281285
sub.setState(Subscription.State.unsubscribed)
282286
})

test/mocha.opts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--colors
2+
--recursive

test/unit/StreamrClient.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ describe('StreamrClient', () => {
146146
before(() => {
147147
mockery.enable()
148148

149-
mockery.registerMock('ws', (uri, opts) => {
149+
// Must return a function since it's called with new
150+
mockery.registerMock('ws', function(uri, opts) {
150151
wsMockCalls++
151152

152153
// Create new sockets for subsequent calls

0 commit comments

Comments
 (0)