Skip to content

Commit c4dde9d

Browse files
committed
chore(spec): use chai instead of expectations
Closes #57
1 parent 4a4854c commit c4dde9d

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
"body-parser": "^1.10.0",
3434
"browser-launcher": "^1.0.0",
3535
"bundle-loader": "^0.5.2",
36+
"chai": "^1.10.0",
37+
"chai-as-promised": "^4.1.1",
3638
"codeclimate-test-reporter": "0.0.4",
3739
"connect": "^3.3.3",
3840
"css-loader": "^0.9.0",
39-
"expectations": "^0.3.0",
4041
"exports-loader": "^0.6.2",
4142
"express": "^4.10.6",
4243
"glob": "^4.3.2",

spec/cachier/cachier_spec.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11

22
import { Cachier } from '../../src/cachier'
33

4-
function shouldReject(promise) {
5-
return Promise.resolve(promise)
6-
.then(
7-
() => { throw new Error('should not be success') },
8-
() => 'ok, error is thrown'
9-
)
10-
}
11-
124
describe('Cachier', function() {
135

146
let cachier
@@ -30,20 +22,19 @@ describe('Cachier', function() {
3022
describe('.connection', () => {
3123
it('should be a promise which fullfill with the db connection', () => {
3224
return cachier.connection.then(function(db) {
33-
expect(db.constructor + '').toMatch(/DBDatabase/)
25+
expect(db.constructor + '').to.match(/DBDatabase/)
3426
})
3527
})
3628
})
3729

3830
describe('#save', () => {
3931
it('stores a blob', () => {
4032
let blob = new Blob(['hello'])
41-
return cachier.save('wow', blob)
42-
.then(result => expect(result).toBeTruthy())
33+
return expect(cachier.save('wow', blob)).to.eventually.be.ok
4334
})
4435
it('rejects when key is invalid', () => {
4536
let blob = new Blob(['hello'])
46-
return shouldReject(cachier.save(undefined, blob))
37+
return expect(cachier.save(undefined, blob)).to.be.rejected
4738
})
4839
})
4940

@@ -57,8 +48,8 @@ describe('Cachier', function() {
5748
describe('#load', function() {
5849
it('should return the blob value', () => {
5950
return cachier.load('wow2').then(function({ blob, metadata }) {
60-
expect(blob.size).toBe(5)
61-
expect(metadata).toEqual({ name: 'example1' })
51+
expect(blob.size).to.equal(5)
52+
expect(metadata).to.deep.equal({ name: 'example1' })
6253
})
6354
})
6455
})
@@ -70,16 +61,16 @@ describe('Cachier', function() {
7061
.delay(10) // chrome needs this delay
7162
.then(() => cachier.load('wow2'))
7263
.then(function({ blob, metadata }) {
73-
expect(blob.size).toBe(6)
74-
expect(metadata).toBe(undefined)
64+
expect(blob.size).to.equal(6)
65+
expect(metadata).to.equal(undefined)
7566
})
7667
})
7768
})
7869

7970
describe('#delete', function() {
8071
it('should remove the blob', () => {
81-
return shouldReject(cachier.delete('wow3')
82-
.then(() => cachier.load('wow3')))
72+
return cachier.delete('wow3')
73+
.then(() => expect(cachier.load('wow3')).to.be.rejected)
8374
})
8475
})
8576

@@ -99,8 +90,8 @@ describe('Cachier', function() {
9990
.delay(10)
10091
.then(() => cachier.load('wow4'))
10192
.then(function({ blob }) {
102-
expect(blob.size).toBe(5)
103-
expect(blob.type).toBe('text/plain')
93+
expect(blob.size).to.equal(5)
94+
expect(blob.type).to.equal('text/plain')
10495
})
10596
})
10697
})

spec/dummy/dummy_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
describe('The specs', function() {
33

44
it('runs', function() {
5-
expect({ runs: true }.runs).toBe(true)
5+
expect({ runs: true }.runs).to.equal(true)
66
})
77

88
})

src/test/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import '../polyfill'
55
import 'script!mocha/mocha.js'
66
import 'style!mocha/mocha.css'
77
import 'style!./support/mocha-overrides.css'
8-
import 'expectations'
8+
9+
import chai from 'chai'
10+
import chaiAsPromised from 'chai-as-promised'
911

1012
export function main() {
1113
setupMocha()
@@ -18,6 +20,8 @@ function setupMocha() {
1820
mochaElement.id = 'mocha'
1921
document.body.appendChild(mochaElement)
2022
mocha.setup('bdd')
23+
chai.use(chaiAsPromised)
24+
global.expect = chai.expect
2125
}
2226

2327
function loadSpecs() {

0 commit comments

Comments
 (0)