chai-spies: How to test async callbacks
This file contains 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