単体テスト ( Mocha経由) を介して Linq2IndexedDB (v. 1.0.21) を試していますが、単純な挿入作業を行うことさえできません。(Google Chrome で実行している場合) Linq2IndexedDB.js の 1535 行目で内部例外がスローされます。
Uncaught TypeError: Cannot read property 'version' of undefined
私の単体テストコードは次のようになります。基本的に、「オブジェクトを追加できる」というテストが 1 つあります。
"use strict";
define(["db", "linq2indexeddb", "chai", "underscore", "stacktrace"], function (db, linq2indexeddb, chai, _,
printStacktrace) {
var should = chai.should();
describe("db", function () {
var _db;
function fail(done, reason, err) {
if (typeof reason === "string") {
reason = new Error(reason);
}
if (!reason) {
console.log(typeof done, typeof reason);
reason = new Error("There's been an error, but no reason was supplied!");
var st = printStacktrace({e: reason});
console.log(st);
}
if (typeof done !== "function") {
throw new Error("Was not supplied a function for 'done'!");
}
done(reason);
}
// Bind done as the first argument to the fail function
function bindFail(done, reason) {
if (typeof done !== "function") {
throw new Error("done must be a function");
}
return _.partial(fail, done, reason);
}
beforeEach(function (done) {
_db = linq2indexeddb("test", null, true);
_db.deleteDatabase()
.done(function () {
_db.initialize()
.done(done)
.fail(bindFail(done, "Initializing database failed"));
})
.fail(bindFail(done, "Deleting database failed"));
});
it("can add objects", function (done) {
console.log("Starting test");
var refObj = {"key": "value"};
_db.linq.from("store").insert(refObj, "Key")
.done(function () {
console.log("Added object successfully");
done();
})
.fail(bindFail(done, "Inserting object failed"));
});
});
});
ここで何か間違ったことをしていますか、それとも Linq2IndexedDB (またはその両方) にバグがありますか?
対応するテスト プロジェクトを Githubに配置し、 Karma構成を完備しているため、含まれているテストを簡単に実行できます。Karma の構成は、Chrome がインストールされていることを前提としています。