Software

Skip or Only Run a Test with JavaScript Mocha

[ad_1]

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.

  • 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…

  • Write Better JavaScript with Promises

    You’ve probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don’t see what makes them so special. Can’t you just use a callback? What’s the big deal? In this article, we’ll…

  • External Site Link Favorite Icons Using MooTools and CSS
  • MooTools Clipboard Plugin

    The ability to place content into a user’s clipboard can be extremely convenient for the user. Instead of clicking and dragging down what could be a lengthy document, the user can copy the contents of a specific area by a single click of a mouse.


[ad_2]
Source link
Show More

admin

Makes Noise is a blog where you can find all the juicy details on a variety of topics including health and fitness, technology, lifestyle, entertainment, love and relationships, beauty and makeup, sports and so much more. The blog is updated regularly to make sure you have all the latest and greatest information on the topics that matter most to you.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button