小编Sol*_*dad的帖子

在测试使用qunit显示一个方法的方法时,避免/捕获/验证Javascript警报

我刚开始使用Qunit,想知道是否有办法捕获/验证/省略警报,例如:

function to_test() {
   alert("I'm displaying an alert");
   return 42;
 }
Run Code Online (Sandbox Code Playgroud)

然后有类似的东西:

test("to_test", function() {
  //in this case I'd like to test the alert.
  alerts("I'm displaying an alert", to_test(), "to_test() should display an alert"); 
  equals(42, to_test(), "to_test() should return 42" );  // in this case I'd like to omit the alert
});
Run Code Online (Sandbox Code Playgroud)

我对使用其他单元测试工具的建议持开放态度.

提前致谢!

javascript alert qunit jsunit

7
推荐指数
1
解决办法
5045
查看次数

标签 统计

alert ×1

javascript ×1

jsunit ×1

qunit ×1