-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_test.ts
60 lines (49 loc) · 1.56 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import "https://deno.land/x/indexeddb@1.3.5/polyfill_memory.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import idbatch from "./mod.ts";
import * as idbx from "https://deno.land/x/idbx@v1.1.0/mod.ts"
Deno.test("batch(add,put,del)", async () => {
const db = await idbx.openDB("test", {
version: 1,
upgrade(db) {
db.createObjectStore("test", { keyPath: "id", autoIncrement: true });
},
});
const batch = idbatch(db, [
// create item
{ method: "add", storeName: "test", data: { name: "test" } },
// update item
{ method: "put", storeName: "test", data: { id: 1, name: "test2" } },
// delete item
{ method: "del", storeName: "test", key: 1 },
], "readwrite");
const results = await batch.completed;
assertEquals(results, [
["add", 1],
["put", 1],
["del", true],
]);
db.close();
indexedDB.deleteDatabase("test");
});
Deno.test("batch(get,getAll)", async () => {
const db = await idbx.openDB("test", {
version: 1,
upgrade(db) {
db.createObjectStore("test", { keyPath: "id", autoIncrement: true });
},
});
const store = db.transaction("test", "readwrite").objectStore("test");
await idbx.add(store, { name: "test" });
const batch = idbatch(db, [
// get item
{ method: "get", storeName: "test", query: 1 },
// get all items
{ method: "getAll", storeName: "test" },
], "readonly");
const results = await batch.completed;
assertEquals(results, [
["get", { id: 1, name: "test" }],
["getAll", [{ id: 1, name: "test" }]],
]);
});