@@ -16,6 +16,7 @@ import {
16
16
showReportDialog ,
17
17
wrap ,
18
18
} from '../../src' ;
19
+ import { getDefaultBrowserClientOptions } from './helper/browser-client-options' ;
19
20
import { SimpleTransport } from './mocks/simpletransport' ;
20
21
21
22
const dsn = 'https://[email protected] /4291' ;
@@ -75,7 +76,8 @@ describe('SentryBrowser', () => {
75
76
describe ( 'showReportDialog' , ( ) => {
76
77
describe ( 'user' , ( ) => {
77
78
const EX_USER = { email :
'[email protected] ' } ;
78
- const client = new BrowserClient ( { dsn } , new SimpleTransport ( { dsn } ) ) ;
79
+ const options = getDefaultBrowserClientOptions ( { dsn } ) ;
80
+ const client = new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ;
79
81
const reportDialogSpy = jest . spyOn ( client , 'showReportDialog' ) ;
80
82
81
83
beforeEach ( ( ) => {
@@ -139,53 +141,41 @@ describe('SentryBrowser', () => {
139
141
} ) ;
140
142
141
143
it ( 'should capture a message' , done => {
142
- getCurrentHub ( ) . bindClient (
143
- new BrowserClient (
144
- {
145
- beforeSend : ( event : Event ) : Event | null => {
146
- expect ( event . message ) . toBe ( 'test' ) ;
147
- expect ( event . exception ) . toBeUndefined ( ) ;
148
- done ( ) ;
149
- return event ;
150
- } ,
151
- dsn,
152
- } ,
153
- new SimpleTransport ( { dsn } ) ,
154
- ) ,
155
- ) ;
144
+ const options = getDefaultBrowserClientOptions ( {
145
+ beforeSend : ( event : Event ) : Event | null => {
146
+ expect ( event . message ) . toBe ( 'test' ) ;
147
+ expect ( event . exception ) . toBeUndefined ( ) ;
148
+ done ( ) ;
149
+ return event ;
150
+ } ,
151
+ dsn,
152
+ } ) ;
153
+ getCurrentHub ( ) . bindClient ( new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ) ;
156
154
captureMessage ( 'test' ) ;
157
155
} ) ;
158
156
159
157
it ( 'should capture an event' , done => {
160
- getCurrentHub ( ) . bindClient (
161
- new BrowserClient (
162
- {
163
- beforeSend : ( event : Event ) : Event | null => {
164
- expect ( event . message ) . toBe ( 'event' ) ;
165
- expect ( event . exception ) . toBeUndefined ( ) ;
166
- done ( ) ;
167
- return event ;
168
- } ,
169
- dsn,
170
- } ,
171
- new SimpleTransport ( { dsn } ) ,
172
- ) ,
173
- ) ;
158
+ const options = getDefaultBrowserClientOptions ( {
159
+ beforeSend : ( event : Event ) : Event | null => {
160
+ expect ( event . message ) . toBe ( 'event' ) ;
161
+ expect ( event . exception ) . toBeUndefined ( ) ;
162
+ done ( ) ;
163
+ return event ;
164
+ } ,
165
+ dsn,
166
+ } ) ;
167
+ getCurrentHub ( ) . bindClient ( new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ) ;
174
168
captureEvent ( { message : 'event' } ) ;
175
169
} ) ;
176
170
177
171
it ( 'should not dedupe an event on bound client' , async ( ) => {
178
172
const localBeforeSend = jest . fn ( ) ;
179
- getCurrentHub ( ) . bindClient (
180
- new BrowserClient (
181
- {
182
- beforeSend : localBeforeSend ,
183
- dsn,
184
- integrations : [ ] ,
185
- } ,
186
- new SimpleTransport ( { dsn } ) ,
187
- ) ,
188
- ) ;
173
+ const options = getDefaultBrowserClientOptions ( {
174
+ beforeSend : localBeforeSend ,
175
+ dsn,
176
+ integrations : [ ] ,
177
+ } ) ;
178
+ getCurrentHub ( ) . bindClient ( new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ) ;
189
179
190
180
captureMessage ( 'event222' ) ;
191
181
captureMessage ( 'event222' ) ;
@@ -197,16 +187,12 @@ describe('SentryBrowser', () => {
197
187
198
188
it ( 'should use inboundfilter rules of bound client' , async ( ) => {
199
189
const localBeforeSend = jest . fn ( ) ;
200
- getCurrentHub ( ) . bindClient (
201
- new BrowserClient (
202
- {
203
- beforeSend : localBeforeSend ,
204
- dsn,
205
- integrations : [ new Integrations . InboundFilters ( { ignoreErrors : [ 'capture' ] } ) ] ,
206
- } ,
207
- new SimpleTransport ( { dsn } ) ,
208
- ) ,
209
- ) ;
190
+ const options = getDefaultBrowserClientOptions ( {
191
+ beforeSend : localBeforeSend ,
192
+ dsn,
193
+ integrations : [ new Integrations . InboundFilters ( { ignoreErrors : [ 'capture' ] } ) ] ,
194
+ } ) ;
195
+ getCurrentHub ( ) . bindClient ( new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ) ;
210
196
211
197
captureMessage ( 'capture' ) ;
212
198
@@ -267,7 +253,8 @@ describe('SentryBrowser initialization', () => {
267
253
} ) ;
268
254
269
255
it ( 'should set SDK data when instantiating a client directly' , ( ) => {
270
- const client = new BrowserClient ( { dsn } , new SimpleTransport ( { dsn } ) ) ;
256
+ const options = getDefaultBrowserClientOptions ( { dsn } ) ;
257
+ const client = new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ;
271
258
272
259
const sdkData = ( client . getTransport ( ) as any ) . _api . metadata ?. sdk ;
273
260
@@ -309,20 +296,16 @@ describe('SentryBrowser initialization', () => {
309
296
310
297
describe ( 'wrap()' , ( ) => {
311
298
it ( 'should wrap and call function while capturing error' , done => {
312
- getCurrentHub ( ) . bindClient (
313
- new BrowserClient (
314
- {
315
- beforeSend : ( event : Event ) : Event | null => {
316
- expect ( event . exception ! . values ! [ 0 ] . type ) . toBe ( 'TypeError' ) ;
317
- expect ( event . exception ! . values ! [ 0 ] . value ) . toBe ( 'mkey' ) ;
318
- done ( ) ;
319
- return null ;
320
- } ,
321
- dsn,
322
- } ,
323
- new SimpleTransport ( { dsn } ) ,
324
- ) ,
325
- ) ;
299
+ const options = getDefaultBrowserClientOptions ( {
300
+ beforeSend : ( event : Event ) : Event | null => {
301
+ expect ( event . exception ! . values ! [ 0 ] . type ) . toBe ( 'TypeError' ) ;
302
+ expect ( event . exception ! . values ! [ 0 ] . value ) . toBe ( 'mkey' ) ;
303
+ done ( ) ;
304
+ return null ;
305
+ } ,
306
+ dsn,
307
+ } ) ;
308
+ getCurrentHub ( ) . bindClient ( new BrowserClient ( options , new SimpleTransport ( { dsn } ) ) ) ;
326
309
327
310
try {
328
311
wrap ( ( ) => {
0 commit comments