Skip to content

Commit

Permalink
increase test coverage and add linter to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Forster committed Jun 23, 2018
1 parent 91d0b6a commit 36afda6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "tape test.js",
"test-pretty": "tape test.js | faucet",
"test-travis": "nyc tape test.js | tap-spec",
"test-travis": "standard && nyc tape test.js | tap-spec",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"keywords": [
Expand Down
32 changes: 32 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,35 @@ tape('promise queue is reuseable as a promise', (t) => {
})
})

tape('if promise queue has callback it cannot be used as promise', (t) => {
const finished = () => {}
const queue = new PromiseQueue(finished)
t.throws(() => queue.then(), /Cannot use PromiseQueue as a Promise if callback has been is set/)
t.throws(() => queue.catch(), /Cannot use PromiseQueue as a Promise if callback has been is set/)
t.end()
})

tape('throws error if queue.add() is not passed a function', (t) => {
const finished = () => {}
const queue = new PromiseQueue(finished)
t.throws(() => queue.add(), /PromiseQueue.add\(\) expects a function as an argument/)
t.end()
})

tape('queue.add() handles non promise returning functions', (t) => {
const finished = () => { t.end() }
const queue = new PromiseQueue(finished)
queue.add(() => 1).then(res => t.same(res, 1))
})

tape('queue.add() handles non promise returning functions that throw', (t) => {
const queue = new PromiseQueue()
queue.add(() => { throw new Error('failed') })
.then(
() => t.fail('should have actually thrown error'),
(e) => {
t.same(e.message, 'failed')
t.end()
}
)
})

0 comments on commit 36afda6

Please sign in to comment.