【问题标题】:Js test function that does not return anything不返回任何内容的js测试函数
【发布时间】:2015-11-18 19:26:16
【问题描述】:

我正在使用 mocha 和 sinon。例如,我有这个功能:

function doSomething(param) {

   if(param === 'something') { // do something }

}

我如何创建测试来检查条件是否为真然后函数不执行任何操作?

it('should do something if param equal something', function() {
   // this part i know
});

it('should not do anything if param not equal something', function() {
   // how to test this part?
});

【问题讨论】:

    标签: javascript unit-testing mocha.js sinon


    【解决方案1】:

    你可以随时检查函数是否返回未定义。函数总是返回一些东西。当你没有明确返回任何东西时,它会返回 undefined。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多