JasmineJS - 非数字检查
Jasmine 提供了一个特殊的匹配器来检查这种特殊类型的测试场景,即 toBeNaN()。
让我们使用以下代码修改我们的 customerMatcher.js。
describe("Different Methods of Expect Block",function () { it("Example of toBeNaN()", function () { expect(0 / 0).toBeNaN(); }); });
这里我们想测试"0/0"的值是多少,但无法确定。因此,这段代码将生成以下绿色屏幕截图。
现在让我们再次使用以下逻辑修改代码,我们将一个变量exp赋值为25,并期望结果不是1除以5的数字。
describe("Different Methods of Expect Block",function () { var exp = 25; it("Example of toBeNaN()", function () { expect(exp/5).toBeNaN(); }); });
这段代码将产生以下输出。