Skip or Only Run a Test with JavaScript Mocha

By  on  

Whenever I start to feel anxiety about a big change I'm making, I start writing more unit tests. I'll write down my fear and then write a test that attacks, and eventually relaxes, that fear. There are two actions that I've been frequently using with test writing: skipping all but one test or single tests.

Skip a Test

Oftentimes I will create tests with empty bodies so that I don't forget to write them. To skip a test which is incomplete or known to fail, you can use xit:

xit('does the thing I want', () => {

});

Once the test is complete or ready to be applied, you can change xit back to it.

Run a Single Test

To run only a single test with the Mocha test framework, use it.only:

it.only('does the thing I want', () => {

});

it.only is especially helpful if you have a large test suite and just want the result of a work-in-progress test quickly.

Let's be honest: writing tests isn't very fun. Like taking your cousin to the school dance or changing a diaper. But test writing is important enough to save yourself, and more importantly, your users, from disaster.

Recent Features

  • By
    Animated 3D Flipping Menu with CSS

    CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more.  I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Cross Browser CSS Box Shadows

    Box shadows have been used on the web for quite a while, but they weren't created with CSS -- we needed to utilize some Photoshop game to create them.  For someone with no design talent, a.k.a me, the need to use Photoshop sucked.  Just because we...

  • By
    Fancy FAQs with jQuery Sliders

    Frequently asked questions can be super boring, right? They don't have to be! I've already shown you how to create fancy FAQs with MooTools -- here's how to create the same effect using jQuery. The HTML Simply a series of H3s and DIVs wrapper...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!