Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions __mocks__/react-native-mmkv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const sharedMockStorage = new Map<string, string>();

const createMockStorage = () => {
const mockGetString = jest.fn((key: string): string | undefined =>
sharedMockStorage.get(key),
);

const mockSet = jest.fn((key: string, value: string): void => {
sharedMockStorage.set(key, value);
});

const mockRemove = jest.fn((key: string): void => {
sharedMockStorage.delete(key);
});

return {
getString: mockGetString,
set: mockSet,
remove: mockRemove,
clearAll: jest.fn((): void => {
sharedMockStorage.clear();
}),
getAllKeys: jest.fn(
(): Array<string> => Array.from(sharedMockStorage.keys()),
),
contains: jest.fn((key: string): boolean => sharedMockStorage.has(key)),
getNumber: jest.fn((key: string): number | undefined => {
const value = sharedMockStorage.get(key);
return value ? Number(value) : undefined;
}),
getBoolean: jest.fn((key: string): boolean | undefined => {
const value = sharedMockStorage.get(key);
if (value === undefined) {
return undefined;
}
return value === 'true';
}),
setNumber: jest.fn((key: string, value: number): void => {
sharedMockStorage.set(key, String(value));
}),
setBoolean: jest.fn((key: string, value: boolean): void => {
sharedMockStorage.set(key, String(value));
}),
};
};

export function createMMKV(_options?: { id?: string }) {
return createMockStorage();
}
12 changes: 0 additions & 12 deletions __tests__/components/providers/auth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ import {
useAuth,
} from '../../../src/components/providers/auth';

// Mock MMKV Storage
jest.mock('react-native-mmkv', () => {
const mockStorage = new Map();
return {
MMKV: jest.fn().mockImplementation(() => ({
set: (key: string, value: string) => mockStorage.set(key, value),
getString: (key: string) => mockStorage.get(key) ?? null,
delete: (key: string) => mockStorage.delete(key),
})),
};
});

// Mock API client interceptors
jest.mock('@/api', () => ({
client: {
Expand Down
28 changes: 14 additions & 14 deletions __tests__/lib/storage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { type MMKV } from 'react-native-mmkv';

import { getItem, removeItem, setItem, storage } from '@/lib/storage';

const TEST_VALUE = 123;
const TEST_NUMBER = 42;

// Mock react-native-mmkv
jest.mock('react-native-mmkv', () => ({
MMKV: jest.fn().mockImplementation(() => ({
getString: jest.fn(),
set: jest.fn(),
delete: jest.fn(),
})),
}));

// Note: The mock is already set up globally in jest-setup.ts
// We just need to cast the storage to access jest mock functions
function setupMockStorage() {
const mockStorage = storage as jest.Mocked<MMKV>;
const mockStorage = storage as unknown as {
getString: jest.Mock;
set: jest.Mock;
remove: jest.Mock;
};
jest.clearAllMocks();
return mockStorage;
}

describe('storage utilities', () => {
let mockStorage: jest.Mocked<MMKV>;
let mockStorage: {
getString: jest.Mock;
set: jest.Mock;
remove: jest.Mock;
};

beforeEach(() => {
mockStorage = setupMockStorage();
Expand Down Expand Up @@ -83,10 +83,10 @@ describe('storage utilities', () => {
});

describe('removeItem', () => {
it('should delete the key from storage', async () => {
it('should remove the key from storage', async () => {
await removeItem('test-key');

expect(mockStorage.delete).toHaveBeenCalledWith('test-key');
expect(mockStorage.remove).toHaveBeenCalledWith('test-key');
});
});
});
9 changes: 9 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines-per-function */
import type { ConfigContext, ExpoConfig } from '@expo/config';
import type { AppIconBadgeConfig } from 'app-icon-badge/types';

Expand Down Expand Up @@ -61,6 +62,14 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
bundler: 'metro',
},
plugins: [
[
'expo-build-properties',
{
ios: {
deploymentTarget: '16.0',
},
},
],
[
'expo-splash-screen',
{
Expand Down
2 changes: 2 additions & 0 deletions jest-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ import '@testing-library/react-native/extend-expect';
global.window = {};
// @ts-ignore
global.window = global;

jest.mock('react-native-mmkv');
65 changes: 34 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,54 @@
"e2e-test": "maestro test .maestro/ -e APP_ID=com.obytes.development"
},
"dependencies": {
"@expo/metro-runtime": "^5.0.5",
"@expo/metro-runtime": "^6.1.2",
"@gorhom/bottom-sheet": "^5.0.5",
"@hookform/resolvers": "^3.9.0",
"@lukemorales/query-key-factory": "^1.3.4",
"@shopify/flash-list": "1.7.6",
"@shopify/flash-list": "2.0.2",
"@tanstack/react-query": "^5.52.1",
"@testing-library/react-hooks": "^8.0.1",
"app-icon-badge": "^0.1.2",
"axios": "^1.7.5",
"dayjs": "^1.11.13",
"expo": "~53.0.23",
"expo-constants": "~17.1.7",
"expo-crypto": "^14.1.5",
"expo-dev-client": "~5.2.4",
"expo-font": "~13.3.2",
"expo-image": "~2.4.0",
"expo-linking": "~7.1.7",
"expo-localization": "~16.1.6",
"expo-router": "~5.1.7",
"expo-splash-screen": "~0.30.10",
"expo-status-bar": "~2.2.3",
"expo-system-ui": "~5.0.11",
"expo": "~54.0.32",
"expo-build-properties": "^1.0.10",
"expo-constants": "~18.0.13",
"expo-crypto": "^15.0.8",
"expo-dev-client": "~6.0.20",
"expo-font": "~14.0.11",
"expo-image": "~3.0.11",
"expo-linking": "~8.0.11",
"expo-localization": "~17.0.8",
"expo-router": "~6.0.22",
"expo-splash-screen": "~31.0.13",
"expo-status-bar": "~3.0.9",
"expo-system-ui": "~6.0.9",
"i18next": "^23.14.0",
"lodash.memoize": "^4.1.2",
"moti": "^0.29.0",
"nativewind": "^4.1.21",
"react": "19.0.0",
"react-dom": "19.0.0",
"react": "19.1.0",
"react-dom": "19.1.0",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.53.0",
"react-i18next": "^15.0.1",
"react-native": "0.79.5",
"react-native": "0.81.5",
"react-native-edge-to-edge": "^1.6.0",
"react-native-flash-message": "^0.4.2",
"react-native-gesture-handler": "~2.24.0",
"react-native-keyboard-controller": "^1.17.4",
"react-native-mmkv": "~3.1.0",
"react-native-reanimated": "~3.17.5",
"react-native-gesture-handler": "~2.28.0",
"react-native-keyboard-controller": "^1.18.5",
"react-native-mmkv": "~4.0.1",
"react-native-nitro-modules": "^0.31.10",
"react-native-reanimated": "~4.1.5",
"react-native-restart": "0.0.27",
"react-native-safe-area-context": "5.4.0",
"react-native-screens": "^4.11.1",
"react-native-svg": "~15.11.2",
"react-native-safe-area-context": "5.6.2",
"react-native-screens": "^4.16.0",
"react-native-svg": "~15.12.1",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "~0.20.0",
"react-native-webview": "13.13.5",
"react-native-web": "~0.21.2",
"react-native-webview": "13.15.0",
"react-native-worklets": "0.5.1",
"react-query-kit": "^3.3.0",
"tailwind-variants": "^0.2.1",
"zod": "^3.23.8",
Expand All @@ -118,15 +121,15 @@
"@dev-plugins/react-query": "^0.0.7",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.28.0",
"@expo/config": "~11.0.10",
"@expo/config": "~12.0.13",
"@tanstack/eslint-plugin-query": "^5.62.1",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react-native": "^12.7.2",
"@types/i18n-js": "^3.8.9",
"@types/invariant": "^2.2.37",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.14",
"@types/lodash.memoize": "^4.1.9",
"@types/react": "~19.0.14",
"@types/react": "~19.1.17",
"@typescript-eslint/eslint-plugin": "^8.34.0",
"@typescript-eslint/parser": "^8.34.0",
"babel-plugin-module-resolver": "^5.0.2",
Expand All @@ -151,14 +154,14 @@
"husky": "^9.1.5",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-expo": "~53.0.10",
"jest-expo": "~54.0.16",
"jest-junit": "^16.0.0",
"lint-staged": "^15.2.9",
"np": "^10.0.7",
"prettier": "^3.3.3",
"tailwindcss": "3.4.4",
"ts-jest": "^29.1.2",
"typescript": "^5.8.3",
"typescript": "^5.9.3",
"typescript-eslint": "^8.34.0"
},
"repository": {
Expand Down
Loading