Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
}

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
11 changes: 11 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,11 @@
@react_error_boundary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used / required? I don't see @react_error_boundary defined anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. Deleted.

Feature: React Error Boundary support
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Feature: React Error Boundary support
Feature: ReactNative ErrorBoundary support


Scenario: basic error boundary usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Scenario: basic error boundary usage
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