Skip to content

Commit

Permalink
Throw when passing undefined to unlisten
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Jun 6, 2015
1 parent c9462ba commit 4998c6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/alt/store/AltStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class AltStore {
}

unlisten(cb) {
if (!cb) throw new TypeError('Unlisten must receive a function')
this[Sym.LIFECYCLE].emit('unlisten')
this[EE].removeListener('change', cb)
}
Expand Down
6 changes: 5 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ const tests = {

assert(myStore.getState().name === 'badger', 'new store state present')
assert.ok(mooseChecker.calledOnce)

assert.throws(() => {
myStore.unlisten()
})
},

'unlisten lifecycle hook'() {
Expand All @@ -591,7 +595,7 @@ const tests = {
const store = alt.createStore(XStore)

// unlisten directly
store.listen()()
store.listen(function () { })()

assert.ok(unlistener.calledOnce, 'unlisten lifecycle hook called')
},
Expand Down

0 comments on commit 4998c6a

Please sign in to comment.