Skip to content

Commit

Permalink
Update delete test
Browse files Browse the repository at this point in the history
(do not ignore delete error on any platform)
  • Loading branch information
Christopher J. Brody committed Dec 10, 2017
1 parent 4e80bd3 commit a61b965
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ var mytests = function() {
}
}

test_it(suiteName + ' test sqlitePlugin.deleteDatabase()', function () {
stop();
it(suiteName + ' test sqlitePlugin.deleteDatabase()', function (done) {
var db = openDatabase("DB-Deletable", "1.0", "Demo", DEFAULT_SIZE);

function createAndInsertStuff() {
Expand All @@ -155,19 +154,28 @@ var mytests = function() {
tx.executeSql('INSERT INTO test VALUES (?)', ['foo']);
});
}, function (err) {
ok(false, 'create and insert tx failed with ERROR: ' + JSON.stringify(err));
// NOT EXPECTED:
console.log('create and insert tx failed with ERROR: ' + JSON.stringify(err));
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();

}, function () {
// check that we can read it
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM test', [], function (tx, res) {
equal(res.rows.item(0).name, 'foo');
});
}, function (err) {
ok(false, 'SELECT tx failed with ERROR: ' + JSON.stringify(err));
// NOT EXPECTED:
console.log('SELECT tx failed with ERROR: ' + JSON.stringify(err));
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();
}, function () {
deleteAndConfirmDeleted();
});
Expand All @@ -182,30 +190,38 @@ var mytests = function() {
db.transaction(function (tx) {
tx.executeSql('SELECT name FROM test', []);
}, function (err) {
ok(true, 'got an expected transaction error');
// EXPECTED RESULT:
expect(err).toBeDefined();
expect(err.message).toBeDefined();
testDeleteError();
}, function () {
// SUCCESS CALLBACK NOT EXPECTED:
console.log('UNEXPECTED SUCCESS: expected a transaction error');
ok(false, 'expected a transaction error');
start();
expect(false).toBe(true);
done();
});
}, function (err) {
// NOT EXPECTED - DO NOT IGNORE ON ANY PLATFORM:
console.log("ERROR: " + JSON.stringify(err));
ok(false, 'error: ' + err);
start();
expect(false).toBe(true);
expect(err).toBeDefined();
expect(err.message).toBeDefined();
expect(err.message).toBe('--');
done();
});
}

function testDeleteError() {
// should throw an error if the db doesn't exist
deleteDatabase("Foo-Doesnt-Exist", function () {
// SUCCESS CALLBACK NOT EXPECTED:
console.log('UNEXPECTED SUCCESS: expected a delete error');
ok(false, 'expected error');
start();
expect(false).toBe(true);
done();
}, function (err) {
ok(!!err, 'got error like we expected');

start();
// EXPECTED RESULT:
expect(err).toBeDefined();
done();
});
}

Expand Down

0 comments on commit a61b965

Please sign in to comment.