Automated Testing Mocha

Running a single Mocha Test

If you want to run a single mocha spec, you just specify the individual file to the mocha command:

mocha specs/ralphsays-spec.js 

But what if you want to run a single test within that file?

What I initially did was comment out the other tests temporarily, but this isn’t efficient or foolproof. I found there’s an .only() method for a test, so you simply use this on the only test you want to run.'shows a quote container', function() {
    var ralphSaysPage = new RalphSaysPage(driver, true);
    ralphSaysPage.quoteContainerPresent().then(function(present) {
        assert.equal(present, true, "Quote container not displayed");

This means you run the same mocha command but it only runs the single test you marked. Neat.

3 replies on “Running a single Mocha Test”

Leave a Reply

Your email address will not be published.