Commit 5320f6cf authored by Hubert SABLONNIERE's avatar Hubert SABLONNIERE

add dirty-chai so we can have real function calls in assertions

parent c2adef22
......@@ -24,6 +24,7 @@
:uri-istanbul: https://istanbul.js.org/
:uri-chai-as-promised: https://github.com/domenic/chai-as-promised
:uri-chai-spies: https://github.com/chaijs/chai-spies
:uri-dirty-chai: https://github.com/prodatakey/dirty-chai
== You're Invited
......@@ -323,6 +324,7 @@ You'll find the documentation for their APIs here:
* {uri-chai-as-promised}[chai-as-promised] to test promises
* {uri-chai-spies}[chai-spies] to create and test spies on callbacks
* {uri-dirty-chai}[dirty-chai] to provide real callable functions instead of function expressions for assertions
If you're working on tests or refactoring tested code, you can run the test suite continuously, using:
......
......@@ -18,6 +18,10 @@ describe('text-utils#capitalize', () => {
const text = 'hello'
const capitalizedText = capitalize(text)
expect(capitalizedText).to.equal('Hello')
// All assertion should be function calls and not just expressions like "to.be.true"
// https://eslint.org/docs/rules/no-unused-expressions
// this is provided by the dirty-chai plugin
expect(capitalizedText === 'Hello').to.be.true()
})
it('should lowercase other letters', () => {
......@@ -121,8 +125,8 @@ describe('text-utils#capitalizeStream', () => {
return expect(capitalizedArray).to.be.fulfilled.and.to.eventually.eql(['Zero', 'One', 'Two', 'Three'])
.then(() => {
// callback need to be tested asynchronously (after the stream is finished)
expect(errorCallback).not.to.have.been.called
expect(endCallback).to.have.been.called.once
expect(errorCallback).not.to.have.been.called()
expect(endCallback).to.have.been.called.once()
})
})
......@@ -136,9 +140,8 @@ describe('text-utils#capitalizeStream', () => {
// don't forget to return the promise as the result of the it() test function!
return expect(capitalizedArray).to.be.rejectedWith(TypeError)
.then(() => {
expect(errorCallback).to.have.been.called.once
expect(endCallback).not.to.have.been.called.once
expect(errorCallback).to.have.been.called.once()
expect(endCallback).not.to.have.been.called.once()
})
})
})
......@@ -9,4 +9,9 @@ chai.use(chaiAsPromised)
const spies = require('chai-spies')
chai.use(spies)
// this must be loaded after the other plugins
// https://github.com/prodatakey/dirty-chai#plugin-assertions
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)
module.exports = { expect, spy: chai.spy }
......@@ -607,6 +607,10 @@ diff@3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"
dirty-chai@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/dirty-chai/-/dirty-chai-2.0.1.tgz#6b2162ef17f7943589da840abc96e75bda01aff3"
dot-prop@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment