Skip to content

Commit f2dafa6

Browse files
Fix crashed last run not returning a value (#4829)
* fix crashed last run * add changelog * Update packages/core/test/wrapper.test.ts
1 parent 241d647 commit f2dafa6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Fixes
1212

13+
- crashedLastRun now returns the correct value ([#4829](https://github.com/getsentry/sentry-react-native/pull/4829))
1314
- Expo Updates Context is passed to native after native init to be available for crashes ([#4808](https://github.com/getsentry/sentry-react-native/pull/4808))
1415
- Expo Updates Context values should all be lowercase ([#4809](https://github.com/getsentry/sentry-react-native/pull/4809))
1516
- Avoid duplicate network requests (fetch, xhr) by default ([#4816](https://github.com/getsentry/sentry-react-native/pull/4816))

packages/core/src/js/wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export const NATIVE: SentryNativeWrapper = {
695695
return null;
696696
}
697697

698-
const result = RNSentry.crashedLastRun();
698+
const result = await RNSentry.crashedLastRun();
699699
return typeof result === 'boolean' ? result : null;
700700
},
701701

packages/core/test/wrapper.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jest.mock('react-native', () => {
1414
addBreadcrumb: jest.fn(),
1515
captureEnvelope: jest.fn(),
1616
clearBreadcrumbs: jest.fn(),
17+
crashedLastRun: jest.fn(),
1718
crash: jest.fn(),
1819
fetchNativeDeviceContexts: jest.fn(() =>
1920
Promise.resolve({
@@ -784,4 +785,27 @@ describe('Tests Native Wrapper', () => {
784785
expect(RNSentry.setContext).toHaveBeenCalledOnce();
785786
});
786787
});
788+
789+
describe('crashedLastRun', () => {
790+
test('return true when promise resolves true ', async () => {
791+
(RNSentry.crashedLastRun as jest.Mock).mockResolvedValue(true);
792+
793+
const result = await NATIVE.crashedLastRun();
794+
expect(result).toBeTrue();
795+
});
796+
797+
test('return true when promise resolves false ', async () => {
798+
(RNSentry.crashedLastRun as jest.Mock).mockResolvedValue(false);
799+
800+
const result = await NATIVE.crashedLastRun();
801+
expect(result).toBeFalse();
802+
});
803+
804+
test('return null when promise does not resolve ', async () => {
805+
(RNSentry.crashedLastRun as jest.Mock).mockResolvedValue(undefined);
806+
807+
const result = await NATIVE.crashedLastRun();
808+
expect(result).toBeNull();
809+
});
810+
});
787811
});

0 commit comments

Comments
 (0)