Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Change default timeout for mocha

Change default timeout for mocha

Quick Answer: Use the --timeout option with the -r flag to specify a global timeout value, e.g. mocha -r 5000 my-spec.js

To change the default timeout for Mocha, you can use the `--timeout` option when running your tests. However, if you want to set a global default timeout that applies to all tests, you'll need to modify the Mocha configuration file.

🚀 How to Resolve This Issue

Method 1: Editing the Mocha Configuration File

  1. Step 1: Open your `package.json` file and add a new configuration option for Mocha.

Method 2: Using the `--require` Option

  1. Step 1: Run Mocha with the `--require` option, specifying a configuration file that sets the default timeout.

✨ Wrapping Up

By following these methods, you can change the default timeout for Mocha and ensure that your tests run within a specific time frame.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions