Mocha uses a default timeout of 2000 ms. However, if for some reason that does not work for your use case, you can increase the timeout for a particular test. In this lesson, you will learn how to increase the timeout of the test using this.timeout()
method.
const bankAccounts = [ { name: 'John', id: 1, account: '347496844548723216', balance: 100 }, { name: 'Jane', id: 2, account: '447496844568723219', balance: 200 } ] module.exports = { getBalance(id, cb) { setTimeout(() => { const { balance } = bankAccounts.find(a => a.id === id); if (!balance) cb('could not find balance'); cb(null, balance) }, 3200) } }
const { expect } = require('chai'); const bankAccount = require('../modules/bank-account'); describe('BankAccount',function(){ this.timeout(3500); it('should get the balance', function(done){ bankAccount.getBalance(1,(err, balance) => { if(err){ throw err; } expect(balance).to.equals(100); done(); }) }) })