Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active June 1, 2018 11:46
Show Gist options
  • Save mrded/643fcbea106a77f873ca605e209dc10c to your computer and use it in GitHub Desktop.
Save mrded/643fcbea106a77f873ca605e209dc10c to your computer and use it in GitHub Desktop.
chai-spies: How to test async callbacks
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