Skip to content

Commit 5099750

Browse files
authored
Added test cases for onError and addOnError callback
* 7765-added test cases for onError and addOnError callback * 7765 added unit test case for addOnError callback * plat-7765 remove spaces
1 parent e815896 commit 5099750

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

packages/react-native/test/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,20 @@ describe('react native notifier', () => {
125125
expect(Bugsnag.isStarted()).toBe(true)
126126
})
127127
})
128+
129+
it('calls addOnError callback for all errors', (done) => {
130+
Bugsnag.start({})
131+
const addOnErrorCb = jest.fn((event) => {
132+
event.addMetadata('addonError', { called: true })
133+
return true
134+
})
135+
Bugsnag.addOnError(addOnErrorCb)
136+
const error = new Error('addonError test')
137+
Bugsnag.notify(error, undefined, (err, event) => {
138+
if (err) return done(err)
139+
expect(addOnErrorCb).toHaveBeenCalledWith(expect.any(Object))
140+
expect(event.getMetadata('addonError')).toEqual({ called: true })
141+
done()
142+
})
143+
})
128144
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import Scenario from './Scenario'
3+
import Bugsnag from '@bugsnag/react-native'
4+
5+
export class AddOnErrorCallbackScenario extends Scenario {
6+
run () {
7+
Bugsnag.addOnError(event => {
8+
event.addMetadata('addonError', { scenario: true })
9+
return true
10+
})
11+
Bugsnag.notify(new Error('addonError scenario test'))
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Scenario from './Scenario'
2+
import Bugsnag from '@bugsnag/react-native'
3+
4+
export class OnErrorCallbackScenario extends Scenario {
5+
run () {
6+
Bugsnag.notify(new Error('addonError scenario test'),event=>{
7+
event.addMetadata('onError', { scenario: true })
8+
})
9+
}
10+
}

test/react-native/features/fixtures/scenario-launcher/scenarios/core/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ export { GroupingDiscriminatorNativeScenario } from './GroupingDiscriminatorNati
8484

8585
// http_errors.feature
8686
export { NetworkRequestScenario } from './NetworkRequestScenario'
87+
88+
export { AddOnErrorCallbackScenario } from './AddOnErrorCallbackScenario'
89+
90+
export { OnErrorCallbackScenario } from './OnErrorCallbackScenario'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: React Native addOnError & onError callbacks
2+
3+
Scenario: Event is modified by addOnError callback
4+
When I run "AddOnErrorCallbackScenario"
5+
Then I wait to receive an error
6+
And the event "metaData.addonError.scenario" is true
7+
8+
Scenario: Event is modified by onError callback
9+
When I run "OnErrorCallbackScenario"
10+
Then I wait to receive an error
11+
And the event "metaData.onError.scenario" is true

0 commit comments

Comments
 (0)