Skip to content

Commit

Permalink
test: increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Feb 19, 2015
1 parent 041ae08 commit 052d7cf
Show file tree
Hide file tree
Showing 6 changed files with 860 additions and 1 deletion.
19 changes: 19 additions & 0 deletions spec/download/download_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import download from 'bemuse/download'

describe('download', function() {

it('resolves with correct type', function() {
return expect(download('/spec/download/fixtures/hello.txt').as('text'))
.to.eventually.match(/hello world/)
})

it('rejects for 404', function() {
return expect(download('/nonexistant').as('blob')).to.be.rejected
})

it('rejects for bad url', function() {
return expect(download('file:///nonexistant').as('blob')).to.be.rejected
})

})
1 change: 1 addition & 0 deletions spec/download/fixtures/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
51 changes: 51 additions & 0 deletions spec/progress/utils_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

import Progress from 'bemuse/progress'
import * as ProgressUtils from 'bemuse/progress/utils'

describe('ProgressUtils', function() {

describe('.fixed', function() {
it('should report for fixed number of items', function() {
let progress = new Progress()
let advance = ProgressUtils.fixed(10, progress)
expect(progress.current).to.equal(0)
expect(progress.total).to.equal(10)
advance('wow')
expect(progress.current).to.equal(1)
expect(progress.total).to.equal(10)
expect(progress.extra).to.equal('wow')
})
})

describe('.wrapPromise', function() {
it('should report number of fulfilled promises', function() {
let progress = new Progress()
let f = ProgressUtils.wrapPromise(progress, promise => promise)
let a = f(new Promise(() => {}))
let b = f(Promise.resolve(1))
let c = f(Promise.reject(new Error('no')))
let d = f(Promise.resolve(3))
void a
void c
return Promise.all([b, d]).then(() => {
expect(progress.current).to.equal(2)
expect(progress.total).to.equal(4)
})
})
})

describe('.bind', function() {
it('should bind from one progress to another', function() {
let a = new Progress()
let b = new Progress()
a.report(10, 20)
ProgressUtils.bind(a, b)
expect(b.current).to.equal(10)
expect(b.total).to.equal(20)
a.report(15, 25)
expect(b.current).to.equal(15)
expect(b.total).to.equal(25)
})
})

})
1 change: 1 addition & 0 deletions spec/resources/fixtures/b/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files":[{"name":"do.mp3","ref":[0,0,30093]},{"name":"mi.mp3","ref":[0,30093,60186]},{"name":"sol.mp3","ref":[0,60186,90279]}],"refs":[{"path":"mp3.0.ea6087c3.bemuse","hash":"ea6087c3379bce007e50c3100b99b83c"}]}
Loading

0 comments on commit 052d7cf

Please sign in to comment.