Skip to content

Commit 6192b13

Browse files
[FSSDK-10936] test improvement
1 parent 960eaec commit 6192b13

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

lib/utils/cache/async_storage_cache.react_native.spec.ts

+9-19
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
import { vi, describe, it, expect } from 'vitest';
1818
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';
2020

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');
2622

2723
type TestData = {
2824
a: number;
@@ -31,15 +27,15 @@ type TestData = {
3127
};
3228

3329
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 () => {
3533
const cache = new AsyncStorageCache<TestData>();
3634

3735
const data = { a: 1, b: '2', d: { e: true } };
3836
await cache.set('key', data);
3937

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));
4339
expect(await cache.get('key')).toEqual(data);
4440
});
4541

@@ -69,23 +65,17 @@ describe('AsyncStorageCache', () => {
6965
await cache.set('key', 'value');
7066
await cache.remove('key');
7167

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();
7569
});
7670

7771
it('should remove all keys from async storage when clear is called', async () => {
7872
const cache = new AsyncStorageCache<string>();
7973
await cache.set('key1', 'value1');
8074
await cache.set('key2', 'value2');
8175

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);
8577
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);
8979
});
9080

9181
it('should return all keys when getKeys is called', async () => {

tests/reactNativeAsyncStorageCache.spec.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@
1616

1717
import { describe, beforeEach, it, vi, expect } from 'vitest';
1818
import ReactNativeAsyncStorageCache from '../lib/plugins/key_value_cache/reactNativeAsyncStorageCache';
19-
import AsyncStorage from '../__mocks__/@react-native-async-storage/async-storage';
2019

21-
vi.mock('../lib/utils/import.react_native/@react-native-async-storage/async-storage', () => {
22-
return {
23-
getDefaultAsyncStorage: () => AsyncStorage,
24-
};
25-
});
20+
vi.mock('@react-native-async-storage/async-storage')
2621

2722
describe('ReactNativeAsyncStorageCache', () => {
2823
const TEST_OBJECT_KEY = 'testObject';

0 commit comments

Comments
 (0)