-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a69821d
commit aafffa2
Showing
4 changed files
with
82 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ jobs: | |
- name: Run npm Install | ||
run: npm install | ||
|
||
# TODO: Check Lint | ||
- name: Unit Tests | ||
run: npm run test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,60 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import { init, sendError } from '../src/RaygunClient'; | ||
import { RaygunClientOptions } from '../src/Types'; | ||
import { cleanup } from '@testing-library/react-native'; | ||
|
||
// jest.mock('../RaygunClient'); | ||
// jest.useFakeTimers(); | ||
|
||
describe('RaygunClient', () => { | ||
// let raygunClient: RaygunClient; | ||
|
||
// beforeEach(() => { | ||
// NativeModules.RaygunNativeBridge = { DEVICE_ID: 'test-device-id' }; | ||
// }); | ||
|
||
it('should send error correctly', async () => { | ||
beforeAll(() => { | ||
const options: RaygunClientOptions = { | ||
apiKey: '',// Your API key | ||
version: '', // Your application version | ||
logLevel: 'off', | ||
enableCrashReporting: true, | ||
enableRealUserMonitoring: false, | ||
disableNativeCrashReporting: true, | ||
}; | ||
|
||
init(options); | ||
|
||
global.fetch = jest.fn(() => | ||
Promise.resolve({ | ||
status: 200, | ||
}) | ||
); | ||
}); | ||
|
||
beforeEach(() => { | ||
fetch.mockClear(); | ||
}); | ||
|
||
afterEach(cleanup); | ||
|
||
it('should send error correctly', async () => { | ||
const error = new Error('Test error'); | ||
await sendError(error); | ||
|
||
// expect(raygunClient.sendError).toHaveBeenCalledWith(error); | ||
// fetch should be called once | ||
expect(fetch).toHaveBeenCalledTimes(1); | ||
|
||
// Capture body from fetch and check if correct | ||
const body = JSON.parse(fetch.mock.calls[0][1].body); | ||
expect(body.Details.Error.Message).toBe('Test error'); | ||
}); | ||
|
||
it('should fail to send error', async () => { | ||
fetch.mockImplementationOnce(() => Promise.reject('API is down')); | ||
const error = new Error('Failed error'); | ||
await sendError(error); | ||
|
||
expect(fetch).toHaveBeenCalledTimes(1); | ||
|
||
// failed to send error should be stored in AsyncStorage | ||
const storedErrors = await AsyncStorage.getItem('raygun4reactnative_local_storage'); | ||
expect(storedErrors).not.toBeNull(); | ||
console.log(storedErrors); | ||
|
||
const errors = JSON.parse(storedErrors); | ||
expect(errors[0].Details.Error.Message).toBe('Failed error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters