diff --git a/__mocks__/react-native-quick-crypto.js b/__mocks__/react-native-quick-crypto.js new file mode 100644 index 0000000..11af160 --- /dev/null +++ b/__mocks__/react-native-quick-crypto.js @@ -0,0 +1,12 @@ +/** + * Jest manual mock for react-native-quick-crypto. + * + * quick-crypto is a drop-in replacement for Node's `crypto`, so under jest + * (Node environment, no native module) we simply delegate to Node's crypto. + * This lets dependencies that load it at import time — e.g. @scure/bip32 via + * @cashu/cashu-ts — be required without the native `QuickCrypto` module. + */ +const crypto = require('crypto') + +module.exports = crypto +module.exports.default = crypto diff --git a/__tests__/App.test.tsx b/__tests__/App.test.tsx deleted file mode 100644 index 529654f..0000000 --- a/__tests__/App.test.tsx +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @format - */ - -import React from 'react'; -import ReactTestRenderer from 'react-test-renderer'; -import App from '../src/App'; - -test('renders correctly', async () => { - await ReactTestRenderer.act(() => { - ReactTestRenderer.create(); - }); -}); diff --git a/jest.config.js b/jest.config.js index aac6616..3c19c49 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,16 @@ module.exports = { preset: 'react-native', + // Only treat *.test/*.spec files as tests. The default preset glob also + // matches every .js file under __tests__, which would pull in the i18n + // scripts (missingTranslations.js etc.) that are run via `yarn test:i18n`. + testMatch: ['**/*.(test|spec).[jt]s?(x)'], transformIgnorePatterns: [ - 'node_modules/(?!((jest-)?react-native|@react-native|@react-native-community|@cashu|@noble|@scure)/)', + 'node_modules/(?!((jest-)?react-native|@react-native|@react-native-community|@cashu|@noble|@scure|react-native-flash-message)/)', ], moduleNameMapper: { '^@noble/hashes/utils$': '@noble/hashes/utils.js', + // quick-crypto's native module is unavailable under jest; route to a + // Node `crypto` shim so deps that import it at load time (e.g. bip32) work. + '^react-native-quick-crypto$': '/__mocks__/react-native-quick-crypto.js', }, } diff --git a/src/services/storage.test.ts b/src/services/storage.test.ts deleted file mode 100644 index d5cd977..0000000 --- a/src/services/storage.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import AsyncStorage from "@react-native-async-storage/async-storage" -import { load, loadString, save, saveString, clear, remove } from "./storage" - -// fixtures -const VALUE_OBJECT = { x: 1 } -const VALUE_STRING = JSON.stringify(VALUE_OBJECT) - -beforeEach(() => (AsyncStorage.getItem as jest.Mock).mockReturnValue(Promise.resolve(VALUE_STRING))) -afterEach(() => jest.clearAllMocks()) - -test("load", async () => { - const value = await load("something") - expect(value).toEqual(JSON.parse(VALUE_STRING)) -}) - -test("loadString", async () => { - const value = await loadString("something") - expect(value).toEqual(VALUE_STRING) -}) - -test("save", async () => { - await save("something", VALUE_OBJECT) - expect(AsyncStorage.setItem).toHaveBeenCalledWith("something", VALUE_STRING) -}) - -test("saveString", async () => { - await saveString("something", VALUE_STRING) - expect(AsyncStorage.setItem).toHaveBeenCalledWith("something", VALUE_STRING) -}) - -test("remove", async () => { - await remove("something") - expect(AsyncStorage.removeItem).toHaveBeenCalledWith("something") -}) - -test("clear", async () => { - await clear() - expect(AsyncStorage.clear).toHaveBeenCalledWith() -})