我正在尝试使用 jasmine 的 beforeAll 和 afterAll 方法,用 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/