JasmineJS - Not a Number Check

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输出