@@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react';
22import * as React from 'react' ;
33import { useState } from 'react' ;
44
5- import { init } from '../src' ;
5+ import { init , getCurrentHub , BrowserClient } from '../src' ;
66import { ErrorBoundary , ErrorBoundaryProps } from '../src/errorboundary' ;
77
88function Boo ( { title } : { title : string } ) : JSX . Element {
@@ -37,18 +37,48 @@ const TestApp: React.FC<ErrorBoundaryProps> = ({ children, ...props }) => {
3737 ) ;
3838} ;
3939
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+ ) ;
4973
5074 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+ >
5282 < h1 > children</ h1 >
5383 </ TestApp > ,
5484 ) ;
0 commit comments