File tree Expand file tree Collapse file tree
tests/unit/storage/providers Expand file tree Collapse file tree Original file line number Diff line number Diff 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
2929describe ( 'createStore - connection resilience' , ( ) => {
You can’t perform that action at this time.
0 commit comments