Created
June 30, 2017 17:33
-
-
Save senica/d793f871fa437b68aee7ba8b3227d330 to your computer and use it in GitHub Desktop.
Allow async/await on mocha it handler.
This file contains hidden or 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
/** | |
* 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