Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allow async/await on mocha it handler.
/**
* If you do:
* describe('Test', ()=>{
* it('what', async (done)=>{
* try{
* await SOME_ASYNC_FUNCTION
* done()
* }catch(e){
* done(e)
* }
* });
* });
*
* You'll most likely get an error:
* Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both.
*
* To solve that, just add these lines before any of your tests.
* It just overwrites the mocha "it" function so not complain about the overspecification.
*/
const _it = it;
global.it = function(txt, cb){
_it(txt, (done)=>{
cb(done);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment