From a69821d30f401e319a237151123358e336bfe698 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Mon, 18 Nov 2024 11:45:54 +0100 Subject: [PATCH] mock asyncstorage --- .../@react-native-async-storage/async-storage.js | 15 ++++++++++++++- sdk/__tests__/RaygunClient.test.tsx | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/sdk/__mocks__/@react-native-async-storage/async-storage.js b/sdk/__mocks__/@react-native-async-storage/async-storage.js index a2542e9..c819283 100644 --- a/sdk/__mocks__/@react-native-async-storage/async-storage.js +++ b/sdk/__mocks__/@react-native-async-storage/async-storage.js @@ -1 +1,14 @@ -export * from '@react-native-async-storage/async-storage/jest/async-storage-mock'; \ No newline at end of file +export * from '@react-native-async-storage/async-storage/jest/async-storage-mock'; + +export default { + getItem: (item, value = null) => { + return new Promise((resolve, reject) => { + resolve(value); + }); + }, + setItem: (item, value) => { + return new Promise((resolve, reject) => { + resolve(value); + }); + } +} \ No newline at end of file diff --git a/sdk/__tests__/RaygunClient.test.tsx b/sdk/__tests__/RaygunClient.test.tsx index a167f47..1878b6a 100644 --- a/sdk/__tests__/RaygunClient.test.tsx +++ b/sdk/__tests__/RaygunClient.test.tsx @@ -1,4 +1,5 @@ import { init, sendError } from '../src/RaygunClient'; +import { RaygunClientOptions } from '../src/Types'; // jest.mock('../RaygunClient'); @@ -9,9 +10,18 @@ describe('RaygunClient', () => { // NativeModules.RaygunNativeBridge = { DEVICE_ID: 'test-device-id' }; // }); - it('should send error correctly', () => { + it('should send error correctly', async () => { + const options: RaygunClientOptions = { + apiKey: '',// Your API key + version: '', // Your application version + enableCrashReporting: true, + enableRealUserMonitoring: false, + disableNativeCrashReporting: true, + }; + + init(options); const error = new Error('Test error'); - sendError(error); + await sendError(error); // expect(raygunClient.sendError).toHaveBeenCalledWith(error); });