Created
November 16, 2015 09:23
-
-
Save garth/7367f25e2dee19f9098a to your computer and use it in GitHub Desktop.
A wrapper for chai that adds a count of the number times expect is called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect as chai } from 'chai'; | |
let expected = null; | |
let actual = 0; | |
export default { | |
expect(target) { | |
actual++; | |
return chai(target); | |
}, | |
expectCount(count) { | |
expected = count; | |
}, | |
reset() { | |
expected = null; | |
actual = 0; | |
}, | |
check() { | |
if (this.currentTest.state === 'failed' || expected === null || expected === actual) { return; } | |
let err = new Error(`expected ${expected} assertions, got ${actual}`); | |
this.currentTest.emit('error', err); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import counter, { expect, expectCount } from './helpers/chaiCounter'; | |
beforeEach(counter.reset); | |
afterEach(counter.check); | |
describe('something', function () { | |
it('should work', function () { | |
// we expect two asserts to be called, if no asserts are made then the test should fail | |
expectCount(2); | |
const state = { | |
set(path, value) { | |
expect(path).to.equal('someKey'); | |
expect(value).to.equal('someValue'); | |
} | |
}; | |
setState(state); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment