Skip to content

Commit 9ea245b

Browse files
committed
added more tests
1 parent 9b625cb commit 9ea245b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ compare tests to node-sqlite3
33

44

55
Int64 tests should cover the default safeIntegers state for statements and transactions
6-
7-
a second database#close test file should test every statement and transaction method on a closed database

test/41.database.close.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var expect = require('chai').expect;
2+
var fs = require('fs');
3+
var Database = require('../.');
4+
var db;
5+
6+
before(function (done) {
7+
db = new Database('temp/' + require('path').basename(__filename).split('.')[0] + '.db');
8+
db.on('open', done);
9+
});
10+
11+
describe('Database#close()', function () {
12+
it('should prevent statements and transactions from operating', function (done) {
13+
db.prepare('CREATE TABLE people (name TEXT)').run();
14+
var stmt1 = db.prepare('SELECT * FROM people');
15+
var stmt2 = db.prepare("INSERT INTO people VALUES ('foobar')");
16+
var trans = db.transaction(["INSERT INTO people VALUES ('foobar')"]);
17+
18+
db.prepare('SELECT * FROM people').bind();
19+
db.prepare("INSERT INTO people VALUES ('foobar')").bind();
20+
db.transaction(["INSERT INTO people VALUES ('foobar')"]).bind();
21+
db.prepare('SELECT * FROM people').get();
22+
db.prepare('SELECT * FROM people').all();
23+
db.prepare('SELECT * FROM people').each(function () {});
24+
db.prepare("INSERT INTO people VALUES ('foobar')").run();
25+
db.transaction(["INSERT INTO people VALUES ('foobar')"]).run();
26+
27+
db.close();
28+
29+
expect(function () {stmt1.bind();}).to.throw(Error);
30+
expect(function () {stmt2.bind();}).to.throw(Error);
31+
expect(function () {trans.bind();}).to.throw(Error);
32+
expect(function () {stmt1.get();}).to.throw(Error);
33+
expect(function () {stmt1.all();}).to.throw(Error);
34+
expect(function () {stmt1.each(function () {});}).to.throw(Error);
35+
expect(function () {stmt2.run();}).to.throw(Error);
36+
expect(function () {trans.run();}).to.throw(Error);
37+
38+
db.on('close', function () {
39+
expect(function () {stmt1.bind();}).to.throw(Error);
40+
expect(function () {stmt2.bind();}).to.throw(Error);
41+
expect(function () {trans.bind();}).to.throw(Error);
42+
expect(function () {stmt1.get();}).to.throw(Error);
43+
expect(function () {stmt1.all();}).to.throw(Error);
44+
expect(function () {stmt1.each(function () {});}).to.throw(Error);
45+
expect(function () {stmt2.run();}).to.throw(Error);
46+
expect(function () {trans.run();}).to.throw(Error);
47+
done();
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)