zoukankan      html  css  js  c++  java
  • [Unit Testing] Set the timeout of a Test in Mocha

    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();
            })
        })
    })
  • 相关阅读:
    AJAX
    正则表达式
    SQL
    foreach 的本质
    C#
    Dojo的subscribe和publish的简单使用
    Dojo的Gridx使用jsonrest需要注意的地方
    如何让Button使用自定义icon
    Djanog结合jquery实现ajax
    如何设置静态文件路径
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8946441.html
Copyright © 2011-2022 走看看