How to Run a Single Test With Mocha?

To run a single test (as defined in it()), you can simply call the only() method on it in the following way:

it.only('...', function () {
  // only this test will run...
});

Similarly, you can call only() on describe if you wish to run all the tests in a single describe() block.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.