starting real testing
This commit is contained in:
@@ -5,3 +5,32 @@ describe("sanity check", () => {
|
|||||||
expect(true).toBeTrue()
|
expect(true).toBeTrue()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("SlopDB Version 1", () => {
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const request = window.indexedDB.deleteDatabase("SlopDB")
|
||||||
|
const deletePromise = new Promise((resolve, reject) => {
|
||||||
|
request.onsuccess = () => {resolve()}
|
||||||
|
request.onerror = (err) => {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return deletePromise
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates a version 1 indexeddb", async () => {
|
||||||
|
const slopdb_v1 = new SlopDB(1)
|
||||||
|
await slopdb_v1.db_opened()
|
||||||
|
expect(slopdb_v1.db).toBeDefined()
|
||||||
|
|
||||||
|
const transaction = slopdb_v1.start_transaction("slop", "readonly")
|
||||||
|
expect(transaction).toBeDefined()
|
||||||
|
|
||||||
|
try {
|
||||||
|
const bad_transaction = slopdb_v1.start_transaction("checkcache", "readonly")
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.name).toBe("NotFoundError")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -34,15 +34,15 @@ export class IDBCursorValueIterator {
|
|||||||
|
|
||||||
|
|
||||||
export class SlopDB {
|
export class SlopDB {
|
||||||
|
open_promise: Promise<IDBDatabase>
|
||||||
db: IDBDatabase
|
db: IDBDatabase
|
||||||
|
|
||||||
constructor(idb_version: number) {
|
constructor(idb_version: number) {
|
||||||
this.open_database(idb_version).then((db) => {
|
this.open_promise = this.open_database(idb_version)
|
||||||
this.db = db
|
}
|
||||||
}).catch((err) => {
|
|
||||||
console.log(err)
|
async db_opened() {
|
||||||
throw err
|
this.db = await this.open_promise
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_db_upgrade(db: IDBDatabase, idb_version: number) {
|
apply_db_upgrade(db: IDBDatabase, idb_version: number) {
|
||||||
@@ -89,6 +89,7 @@ export class SlopDB {
|
|||||||
start_transaction(storeNames: string | Array<string>, mode: IDBTransactionMode, options: IDBTransactionOptions = undefined): IDBTransaction {
|
start_transaction(storeNames: string | Array<string>, mode: IDBTransactionMode, options: IDBTransactionOptions = undefined): IDBTransaction {
|
||||||
return this.db.transaction(storeNames, mode, options)
|
return this.db.transaction(storeNames, mode, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CheckCache {
|
export class CheckCache {
|
||||||
|
|||||||
Reference in New Issue
Block a user