Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Bugsnag from '@bugsnag/react-native'
import * as React from 'react'
import { Text, View } from 'react-native'
import Scenario from './Scenario'

const onError = (event) => {
// callback will only run for errors caught by boundary
event.addMetadata('errorBoundary', 'caughtByErrorBoundary', true)
event.addMetadata('errorBoundary', 'handlerType', 'react-native-error-boundary')
}

export class ReactNativeErrorBoundaryScenario extends Scenario {
view () {
const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React)
return (
<ErrorBoundary FallbackComponent={ErrorView} onError={onError}>
<MainView />
</ErrorBoundary>
)
}

run () {
// Error is thrown during render
}
}

function ErrorView () {
return (
<View>
<Text>There was an error</Text>
</View>
)
}

function MainView () {
return (
<View>
<Text>Hello world {text()}</Text>
</View>
)
}

const text = function () {
throw new Error('borked')
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export { NativeFeatureFlagsScenario } from './NativeFeatureFlagsScenario'
export { ReactNavigationBreadcrumbsEnabledScenario } from './ReactNavigationBreadcrumbsEnabledScenario'
export { ReactNavigationBreadcrumbsDisabledScenario } from './ReactNavigationBreadcrumbsDisabledScenario'

// react-native-error-boundary.feature
export { ReactNativeErrorBoundaryScenario } from './ReactNativeErrorBoundaryScenario'

// react-native-navigation.feature
export { ReactNativeNavigationBreadcrumbsEnabledScenario } from './ReactNativeNavigationBreadcrumbsEnabledScenario'
export { ReactNativeNavigationBreadcrumbsDisabledScenario } from './ReactNativeNavigationBreadcrumbsDisabledScenario'
Expand Down
12 changes: 12 additions & 0 deletions test/react-native/features/react-native-error-boundary.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: ReactNative ErrorBoundary support

Scenario: ErrorBoundary component reports errors
When I run "ReactNativeErrorBoundaryScenario"
And I relaunch the app after a crash
And I configure Bugsnag for "ReactNativeErrorBoundaryScenario"
Then I wait to receive an error
And the exception "errorClass" equals "Error"
And the exception "message" equals "borked"
And the event "metaData.react.componentStack" is not null
And the event "metaData.errorBoundary.caughtByErrorBoundary" is true
And the event "metaData.errorBoundary.handlerType" equals "react-native-error-boundary"