DEV Community

Testing TypeScript with Mocha and Chai

Daniel Werner on August 15, 2019

Introduction I am a huge fan of TDD, already wrote a couple of articles in this topic. In one of my recent projects I used Angular as a ...
Collapse
 
rodrigozan profile image
rodrigozan

Thanks for this post, helped me a lot

Collapse
 
geoffcapper profile image
Geoff

Thanks, this got me up and running with my TS tests. Mocha recommends against using arrow functions for tests (mochajs.org/#arrow-functions). As I'm only new at this, is there a reason to use them in this context?

Collapse
 
daniel_werner profile image
Daniel Werner

Thanks for your note! You are right, it is discouraged to use arrow functions in Mocha, however if you don't need to access the Mocha context (aka this), it works fine.
No special reason to use them here, just a shorter syntax :-)

Collapse
 
rcanu profile image
Reymart Canuel

Very straightforward and easy to follow! Thanks for this post @daniel_werner !

Collapse
 
daniel_werner profile image
Daniel Werner

You are welcome! If you are interested to learn more on testing with Mocha, check out my blog post series on the topic here: danielwerner.dev/category/testing-...

Collapse
 
willemodendaal profile image
Willem Odendaal

Is it possible to use babel/register instead of ts-node/register? Not really sure what the difference is between the two.

Collapse
 
diek profile image
diek

Thank you, i was just now refactoring the suit tests to typescript and i was wondering how to migrate this. Epic :)

Collapse
 
hansoncoding profile image
Hans

👍

Collapse
 
vm31 profile image
vm31

Good explanation helped me quick start testing with mocha and typescript .Thank you!

Collapse
 
bc profile image
Brian Canzanella

Awesome! This got me going in literally less than 2 minutes. Thanks!

Collapse
 
chidioguejiofor profile image
Chidiebere Ogujeiofor

This saved me immensely. Thanks a lot