gpt4 book ai didi

javascript - 使用 Jasmine 进行数据库集成测试

转载 作者:行者123 更新时间:2023-11-28 08:30:51 25 4
gpt4 key购买 nike

我想保证在 Jasmine 集成测试后关闭与数据库的连接。这就是我目前所拥有的 - 它能确保数据库连接正确关闭吗?

"use strict";

describe("MyCtorFunction", function () {

describe("myMethod", function () {
var _db = null,
_testContext = null;

beforeEach(function () {
_testContext = {};
new DbHelper().openConnection(function (err, dbConnection) {
if (err) {
throw err;
}

_db = dbConnection;
});

waitsFor(function () {
return _db;
}, "establishing a connection to the database.", 5000);
});

afterEach(function () {
waitsFor(function () {
return _testContext.assertions.callCount === 1;
}, "waiting for the assertions to be called.", 5000);

runs(function () {
if (_db) {
_db.close();
_db = null;
}
});
});

it("should do something", function () {
runs(function () {
//arrange
_testContext.assertions = assertions;
spyOn(_testContext, "assertions").andCallThrough();

//act (_testContext.assertions invoked as callback)
new MyCtorFunction(_db).myMethod(_testContext.assertions);

//assert
function assertions(err, config) {
expect(config).toNotBe(null);
//etc.
}
});
});
});
});

最佳答案

不,它假设如下:

  • 测试期间网络连接未丢失
  • 断言本身没有语法或引用错误
  • andCallThroughmyMethod 中没有错误

关于javascript - 使用 Jasmine 进行数据库集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21885105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com