2022-01-26 12:08:38 +05:30
|
|
|
/* Setup for unit test environment */
|
2022-08-27 11:52:29 +05:30
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
import { setImmediate } from 'timers';
|
2023-06-20 00:43:36 +05:30
|
|
|
import Dexie from 'dexie';
|
|
|
|
import { IDBKeyRange, IDBFactory } from 'fake-indexeddb';
|
2022-01-26 12:08:38 +05:30
|
|
|
import 'helpers/shared_test_setup';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
const indexedDB = new IDBFactory();
|
|
|
|
|
|
|
|
Dexie.dependencies.indexedDB = indexedDB;
|
|
|
|
Dexie.dependencies.IDBKeyRange = IDBKeyRange;
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
afterEach(() =>
|
|
|
|
// give Promises a bit more time so they fail the right test
|
2022-05-07 20:08:51 +05:30
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-07-07 11:18:12 +05:30
|
|
|
new Promise(setImmediate).then(() => {
|
|
|
|
// wait for pending setTimeout()s
|
2020-04-22 19:07:51 +05:30
|
|
|
jest.runOnlyPendingTimers();
|
2019-07-07 11:18:12 +05:30
|
|
|
}),
|
|
|
|
);
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
const dbs = await indexedDB.databases();
|
|
|
|
|
|
|
|
await Promise.all(dbs.map((db) => indexedDB.deleteDatabase(db.name)));
|
|
|
|
});
|