summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/idb-wpt-ported/value.test.ts
blob: 95712e1523f0ee05cbff34d98e86c09f0acdafa9 (plain)
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
import test from "ava";
import { IDBVersionChangeEvent } from "../idbtypes.js";
import { createdb, initTestIndexedDB } from "./wptsupport.js";

test.before("test DB initialization", initTestIndexedDB);

test("WPT test value.htm, array", (t) => {
  return new Promise((resolve, reject) => {
    const value = new Array();
    const _instanceof = Array;

    t.plan(1);

    createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) {
      (e.target as any).result.createObjectStore("store").add(value, 1);
      (e.target as any).onsuccess = (e: any) => {
        e.target.result
          .transaction("store")
          .objectStore("store")
          .get(1).onsuccess = (e: any) => {
          t.assert(e.target.result instanceof _instanceof, "instanceof");
          resolve();
        };
      };
    };
  });
});

test("WPT test value.htm, date", (t) => {
  return new Promise((resolve, reject) => {
    const value = new Date();
    const _instanceof = Date;

    t.plan(1);

    createdb(t).onupgradeneeded = function (e: IDBVersionChangeEvent) {
      (e.target as any).result.createObjectStore("store").add(value, 1);
      (e.target as any).onsuccess = (e: any) => {
        e.target.result
          .transaction("store")
          .objectStore("store")
          .get(1).onsuccess = (e: any) => {
          t.assert(e.target.result instanceof _instanceof, "instanceof");
          resolve();
        };
      };
    };
  });
});