What do you mean by not having to deal with “done” callbacks when writing async tests with Mocha?
Einar Paul Qvale

That’s because Jasmine v2 picked up a lot during it’s Angular related call to fame, and Mocha is poorly documented.

In Mocha, you can just return a promise. If the promise is rejected, the test fails. So using something like chai as promised, you can do something like:

return expect(myApi.get()).to.eventually.equal({ data: { foo: 123 } });

Or if you needed something more complicated, you could do:

return expect(myApi.get())
 .then((result) => {
 return expect(result).to.deep.equal({ data: { foo: 123 } });

(or something like that. Coding in Medium is hard).

It gives a lot of nice options if your codebase is promise heavy or if you use async/await.

There’s addons to make it work with generators and async/await directly too. That’s something Ava has built in.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.