javascript - before/afterAll() 未在 jasmine-node 中定义

标签 javascript jasmine jasmine-node frisby.js web-api-testing

我正在尝试使用 jasmine 的 beforeAllafterAll 方法,用 frisby.js 创建一套测试,因为实际上,frisby 不支持这种方法。所以,这就是我想要做的:

var frisby = require('frisby');
describe("setUp and tearDown", function(){
    beforeAll(function(){
        console.log("test beforeAll");
    });

    afterAll(function(){
        console.log("afterAll");
    });

//FRISBY TESTS
}); //end of describe function

如果我将 before/afterAll 方法更改为 before/afterEach,则可以正常工作,但是当我使用 before/afterAll 时,控制台上会出现此错误:

Message: ReferenceError: beforeAll is not defined Stacktrace: ReferenceError: beforeAll is not defined

我的项目安装了 jasmine 2.3.2 版本,所以,我不知道我需要做什么来集成这个方法。

最佳答案

使用 jasmine 库而不是 jasmine-node 库。第二个不支持 beforeAll 和 afterAll 方法。

1- npm install -g Jasmine

2- Jasmine 初始化

3- 在 spec 文件夹中编写测试:

  describe("A spec using beforeAll and afterAll", function() {
    var foo;

    beforeAll(function() {
     foo = 1;
    });

    afterAll(function() {
     foo = 0;
    });

    it("sets the initial value of foo before specs run", function() {
      expect(foo).toEqual(1);
      foo += 1;
    });

   it("does not reset foo between specs", function() {
     expect(foo).toEqual(2);
   });
});

4- 运行测试 --> Jasmine

关于javascript - before/afterAll() 未在 jasmine-node 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141307/

相关文章:

angularjs - 试图等待预期元素消失,无法捕获此错误

javascript - 为什么我的 Jasmine 单元测试不等待 'done' ?

javascript - Jasmine-node - 在其他函数内部调用的构造函数上创建 spy

javascript - 显示按字段分组的项目

javascript - 如何通过所选文本获取关闭的父 div 属性?

angular - Jasmine HTTP 测试未覆盖 RXJS 管道

javascript - 带有注入(inject)服务的单元测试 Angular Controller

javascript - 使用 frisby.js 或 jasmine-node 测试证书过期

javascript - 当鼠标悬停在子元素上时如何设置父元素的样式?

javascript - 来自 Controller 的 Angular 设置 ng-minlength 不起作用