JasmineJS教程

JasmineJS 数字检查

Jasmine 提供了一个特殊的匹配器来检查这种特殊类型的测试场景,即 toBeNaN()
让我们使用以下代码修改我们的 customerMatcher.js
describe("Different Methods of Expect Block",function () { 
   it("Example of toBeNaN()", function () { 
      expect(0 / 0).toBeNaN(); 
   });
});
这里我们要测试无法确定的"0/0"的值是多少。因此,这段代码将生成以下绿色屏幕截图。
toBeNan
现在让我们用下面的逻辑再次修改代码,我们将一个变量 exp 赋值给 25,并期望结果不是数字除以 5、
describe("Different Methods of Expect Block",function () { 
   var exp = 25; 
	
   it("Example of toBeNaN()", function () { 
      expect(exp/5).toBeNaN(); 
   });
});
这段代码将产生以下输出。
toBeNan 输出
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4