Skip to content

Instantly share code, notes, and snippets.

@senica
Created June 30, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senica/d793f871fa437b68aee7ba8b3227d330 to your computer and use it in GitHub Desktop.
Save senica/d793f871fa437b68aee7ba8b3227d330 to your computer and use it in GitHub Desktop.
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