- JasmineJS 教程
- JasmineJS - 主页
- JasmineJS - 概述
- JasmineJS - 环境设置
- JasmineJS - 文字编写与执行
- JasmineJS - BDD 架构
- JasmineJS - 测试基础构建块
- JasmineJS - 匹配器
- JasmineJS - 跳过模块
- JasmineJS - 相等性检查
- JasmineJS - 布尔值检查
- JasmineJS - 顺序检查
- JasmineJS - 判空检查
- JasmineJS - 不等性检查
- JasmineJS - 非数字检查
- JasmineJS - 异常检查
- JasmineJS - beforeEach()
- JasmineJS - afterEach()
- JasmineJS - 间谍
- JasmineJS 有用资源
- JasmineJS - 快速指南
- JasmineJS - 有用资源
- JasmineJS - 讨论
JasmineJS - beforeEach()
Jasmine 的另一个显著特点是 before 和 after 每个功能。使用这两个功能,我们可以在执行每个规范之前和之后执行一些代码片段。此功能对于运行应用程序中的公共代码非常有用。让我们创建一个如下所示的规范文件。
var currentVal = 0;
beforeEach(function() {
currentVal = 5;
});
describe("Different Methods of Expect Block",function() {
it("after each function ", function() {
expect(currentVal).toEqual(5);
});
});
虽然我们在开头声明了一个变量为“0”,但我们期望在期待块中此值等于 5。上述代码将生成以下输出。
在上述代码中,将在执行 expect 块之前将 5 分配给变量currentVal。因此,它生成一个没有错误的绿色屏幕截图。
广告