Skip to content

Commit 8aa7ec6

Browse files
committed
fix tests.
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
1 parent 2946a6f commit 8aa7ec6

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

tests/unit/storage/providers/createStoreTest.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ function uniqueDBName() {
1414
* Captures the internal IDBDatabase instance used by a store by intercepting
1515
* the first db.transaction() call.
1616
*/
17-
function captureDB(store: ReturnType<typeof createStore>): Promise<IDBDatabase> {
18-
return new Promise<IDBDatabase>((resolve) => {
19-
const original = IDBDatabase.prototype.transaction;
20-
const spy = jest.spyOn(IDBDatabase.prototype, 'transaction').mockImplementation(function (this: IDBDatabase, ...args) {
21-
spy.mockRestore();
22-
resolve(this);
23-
return original.apply(this, args);
24-
});
25-
store('readonly', (s) => IDB.promisifyRequest(s.getAllKeys()));
17+
async function captureDB(store: ReturnType<typeof createStore>): Promise<IDBDatabase> {
18+
const captured: {db?: IDBDatabase} = {};
19+
const original = IDBDatabase.prototype.transaction;
20+
const spy = jest.spyOn(IDBDatabase.prototype, 'transaction').mockImplementation(function (this: IDBDatabase, ...args) {
21+
captured.db = this;
22+
spy.mockRestore();
23+
return original.apply(this, args);
2624
});
25+
await store('readonly', (s) => IDB.promisifyRequest(s.getAllKeys()));
26+
return captured.db!;
2727
}
2828

2929
describe('createStore - connection resilience', () => {

0 commit comments

Comments
 (0)