I'm having some troubles getting where() statements to work in Dexie. My attempts to use where result in the following error:
console.warn node_modules/dexie/dist/dexie.js:1273 Unhandled rejection: TypeError: Cannot read property 'bound' of undefined at makeIDBKeyRange (node_modules/dexie/src/dbcore/dbcore-indexeddb.ts:112:21) at node_modules/dexie/src/dbcore/dbcore-indexeddb.ts:314:31 ...
Here's the code that I used:
import Dexie from "dexie"; // @ts-ignore there is not a type for the fake indexeddb import indexedDB from 'fake-indexeddb'; class TestDatabase extends Dexie { constructor() { super("test"); this.version(1).stores({ data: "id, name" }); } } test("dexie", async ()=>{ Dexie.dependencies.indexedDB = indexedDB; const db = new TestDatabase(); await db.table("data").put({id: "x", name: "xname"}); const x=await db.table("data").get("x"); expect (x.name).toEqual("xname"); const x2=await db.table("data").where("id").equals("x").toArray() expect (x2[0].name).toEqual("xname"); })
The test appears to be failing at the call to toArray(). How can I get this test to pass?
I think you're missing to set Dexie.dependencies.IDBKeyRange also.
Fake-indexeddb recommends to do the following to integrate fake-indexeddb in node:
const Dexie = require("dexie");
require("fake-indexeddb/auto");
const db = new Dexie("MyDatabase");
See their docs