@@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
2
2
import * as React from 'react' ;
3
3
import { useState } from 'react' ;
4
4
5
- import { init } from '../src' ;
5
+ import { init , getCurrentHub , BrowserClient } from '../src' ;
6
6
import { ErrorBoundary , ErrorBoundaryProps } from '../src/errorboundary' ;
7
7
8
8
function Boo ( { title } : { title : string } ) : JSX . Element {
@@ -37,18 +37,48 @@ const TestApp: React.FC<ErrorBoundaryProps> = ({ children, ...props }) => {
37
37
) ;
38
38
} ;
39
39
40
- describe . only ( 'Integration Test' , ( ) => {
41
- it ( 'captures an error and sends it to Sentry' , ( ) => {
42
- init ( {
43
- dsn : '' ,
44
- beforeSend : event => {
45
- console . log ( event ) ;
46
- return event ;
47
- } ,
48
- } ) ;
40
+ const dsn = 'https://[email protected] /12312012' ;
41
+
42
+ describe ( 'React Integration Test' , ( ) => {
43
+ beforeAll ( ( ) => {
44
+ init ( { dsn } ) ;
45
+ } ) ;
46
+
47
+ beforeEach ( ( ) => {
48
+ jest . clearAllMocks ( ) ;
49
+ getCurrentHub ( ) . pushScope ( ) ;
50
+ } ) ;
51
+
52
+ afterEach ( ( ) => {
53
+ getCurrentHub ( ) . popScope ( ) ;
54
+ } ) ;
55
+
56
+ it ( 'captures an error and sends it to Sentry' , done => {
57
+ let capturedHint ;
58
+ let error : Error ;
59
+ let eventId : string ;
60
+
61
+ expect . assertions ( 6 ) ;
62
+ getCurrentHub ( ) . bindClient (
63
+ new BrowserClient ( {
64
+ beforeSend : ( event : Event ) => {
65
+ expect ( event . tags ) . toEqual ( { test : '1' } ) ;
66
+ expect ( event . exception ) . not . toBeUndefined ( ) ;
67
+ e done ( ) ;
68
+ return null ;
69
+ } ,
70
+ dsn,
71
+ } ) ,
72
+ ) ;
49
73
50
74
render (
51
- < TestApp fallback = { < p > You have hit an error</ p > } >
75
+ < TestApp
76
+ fallback = { < p > You have hit an error</ p > }
77
+ onError = { ( e , _ , id ) => {
78
+ error = e ;
79
+ eventId = id ;
80
+ } }
81
+ >
52
82
< h1 > children</ h1 >
53
83
</ TestApp > ,
54
84
) ;
0 commit comments