Last active
June 1, 2018 11:46
-
-
Save mrded/643fcbea106a77f873ca605e209dc10c to your computer and use it in GitHub Desktop.
chai-spies: How to test async callbacks
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
const Chai = require('chai'); | |
const Spies = require('chai-spies'); | |
Chai.use(Spies); | |
const original = function(callback) { | |
setTimeout(callback, 0); | |
}; | |
it("async callback should be called with Spy", function() { | |
const callback = Chai.spy(); | |
original(callback); | |
// Doesn't work here. | |
Chai.expect(callback).to.have.been.called(); | |
}); | |
it("async callback should be called without Spy", function(done) { | |
// Does work. | |
original(() => done()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment