【问题标题】:Issue catching errors using should.js/Mocha使用 should.js/Mocha 捕获错误
【发布时间】:2019-07-03 20:41:32
【问题描述】:

我目前正在使用 Mocha 和断言库 should.js

我正在尝试在我的单元测试中运行一个会引发异常的情况 - 但从查看文档来看,到目前为止我还没有太多运气让它工作。

目前正在使用以下代码块:

it('Adds a new employee to the db - FAILS', funct
     let employeeObj = {                          
         "Title": "Mr",                           
         "FirstName": "Keanu ",                   
         "LastName": "Reeves",                    
         "Username": "KeanuReeves2",              
         "Password": "Password",                  
         "Email": "keanu@reeves.com", 
         "IsActive": true           
     };                                           
     should(function () {                         
         db.AddNewEmployee(employeeObj);          
     }).throw("U wot m8");                        
     done();                                      
 });            

我不断收到错误:

AssertionError: expected Function { name: '' } to throw exception
    at Assertion.fail (node_modules\should\cjs\should.js:275:17)
    at Assertion.value (node_modules\should\cjs\should.js:356:19)
    at Context.<anonymous> (common\spec\knexDBServiceSpec.js:213:25)

有没有人遇到过这个问题或者能给我一些关于哪里出错的指导?

【问题讨论】:

    标签: node.js mocha.js should.js


    【解决方案1】:

    它完全按照您的设置去做。

    你告诉应该,你的函数应该抛出一个异常“U wot m8”。 但它没有,因此应该失败。

    期望(应该)是它应该抛出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-10
      • 2012-09-14
      • 2014-12-30
      • 1970-01-01
      相关资源
      最近更新 更多