Skip to content

Commit

Permalink
Found issue with that Dexie.Promise.on('error') wasnt signaled for fa…
Browse files Browse the repository at this point in the history
…iled transactionless operations.

This unit test confirms that.
  • Loading branch information
dfahlander committed Apr 8, 2016
1 parent 3ab125f commit e7f3275
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/tests-exception-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ db.on("populate", function (trans) {
users.add({ id: 1, first: "David", last: "Fahlander", username: "dfahlander", email: ["[email protected]", "[email protected]"], pets: ["dog"] });
users.add({ id: 2, first: "Karl", last: "Cedersköld", username: "kceder", email: ["[email protected]"], pets: [] });
});
db.on("error", function (e) {
function dbOnErrorHandler (e) {
ok(false, "An error bubbled out to the db.on('error'). Should not happen because all tests should catch their errors themselves. " + e);
});
}
db.on("error", dbOnErrorHandler);

module("exception-handling", {
setup: function () {
Expand All @@ -24,6 +25,23 @@ module("exception-handling", {
}
});

asyncTest("Uncaught promise should signal to Promise.on('error')", function(){
// We must not use finally or catch here because then we don't test what we should.
var onErrorSignals = 0;
function onerror(e) {
++onErrorSignals;
}
Dexie.Promise.on('error', onerror);
db.on('error').unsubscribe(dbOnErrorHandler);
db.users.add({ id: 1 });
setTimeout(()=> {
equal(onErrorSignals, 1, "Promise.on('error') should have been signaled");
db.on("error", dbOnErrorHandler);
Dexie.Promise.on('error').unsubscribe(onerror);
start();
}, 100);
});

spawnedTest("transaction should abort on collection error", function*(){
yield db.transaction("rw", db.users, function*() {
let id = yield db.users.add({id: 3, first: "Foo", last: "Bar", username: "foobar"});
Expand Down

0 comments on commit e7f3275

Please sign in to comment.