16
16
17
17
import { vi , describe , it , expect } from 'vitest' ;
18
18
import { AsyncStorageCache } from './async_storage_cache.react_native' ;
19
- import AsyncStorage from '../../../__mocks__ /@react-native-async-storage/async-storage' ;
19
+ import { getDefaultAsyncStorage } from '../import.react_native /@react-native-async-storage/async-storage' ;
20
20
21
- vi . mock ( '../lib/utils/import.react_native/@react-native-async-storage/async-storage' , ( ) => {
22
- return {
23
- getDefaultAsyncStorage : ( ) => AsyncStorage ,
24
- } ;
25
- } ) ;
21
+ vi . mock ( '@react-native-async-storage/async-storage' ) ;
26
22
27
23
type TestData = {
28
24
a : number ;
@@ -31,15 +27,15 @@ type TestData = {
31
27
} ;
32
28
33
29
describe ( 'AsyncStorageCache' , ( ) => {
34
- it ( 'should store a stringified value in asyncstorag' , async ( ) => {
30
+ const asyncStorage = getDefaultAsyncStorage ( ) ;
31
+
32
+ it ( 'should store a stringified value in async storage' , async ( ) => {
35
33
const cache = new AsyncStorageCache < TestData > ( ) ;
36
34
37
35
const data = { a : 1 , b : '2' , d : { e : true } } ;
38
36
await cache . set ( 'key' , data ) ;
39
37
40
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
- // @ts -ignore
42
- expect ( await cache . asyncStorage . getItem ( 'key' ) ) . toBe ( JSON . stringify ( data ) ) ;
38
+ expect ( await asyncStorage . getItem ( 'key' ) ) . toBe ( JSON . stringify ( data ) ) ;
43
39
expect ( await cache . get ( 'key' ) ) . toEqual ( data ) ;
44
40
} ) ;
45
41
@@ -69,23 +65,17 @@ describe('AsyncStorageCache', () => {
69
65
await cache . set ( 'key' , 'value' ) ;
70
66
await cache . remove ( 'key' ) ;
71
67
72
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
- // @ts -ignore
74
- expect ( await cache . asyncStorage . getItem ( 'key' ) ) . toBeNull ( ) ;
68
+ expect ( await asyncStorage . getItem ( 'key' ) ) . toBeNull ( ) ;
75
69
} ) ;
76
70
77
71
it ( 'should remove all keys from async storage when clear is called' , async ( ) => {
78
72
const cache = new AsyncStorageCache < string > ( ) ;
79
73
await cache . set ( 'key1' , 'value1' ) ;
80
74
await cache . set ( 'key2' , 'value2' ) ;
81
75
82
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
- // @ts -ignore
84
- expect ( ( await cache . asyncStorage . getAllKeys ( ) ) . length ) . toBe ( 2 ) ;
76
+ expect ( ( await asyncStorage . getAllKeys ( ) ) . length ) . toBe ( 2 ) ;
85
77
cache . clear ( ) ;
86
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
87
- // @ts -ignore
88
- expect ( ( await cache . asyncStorage . getAllKeys ( ) ) . length ) . toBe ( 0 ) ;
78
+ expect ( ( await asyncStorage . getAllKeys ( ) ) . length ) . toBe ( 0 ) ;
89
79
} ) ;
90
80
91
81
it ( 'should return all keys when getKeys is called' , async ( ) => {
0 commit comments