@@ -26,6 +26,9 @@ addDOMPropertiesToGlobal(['XMLHttpRequest', 'Event', 'location', 'document']);
26
26
describe ( 'Hub' , ( ) => {
27
27
afterEach ( ( ) => {
28
28
jest . clearAllMocks ( ) ;
29
+ // Reset global carrier to the initial state
30
+ const hub = new Hub ( ) ;
31
+ makeMain ( hub ) ;
29
32
} ) ;
30
33
31
34
describe ( 'getTransaction()' , ( ) => {
@@ -125,6 +128,13 @@ describe('Hub', () => {
125
128
expect ( transaction . sampled ) . toBe ( true ) ;
126
129
} ) ;
127
130
131
+ it ( 'should set sampled = true if tracesSampleRate is 1 (without global hub)' , ( ) => {
132
+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 1 } ) ) ;
133
+ const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
134
+
135
+ expect ( transaction . sampled ) . toBe ( true ) ;
136
+ } ) ;
137
+
128
138
it ( "should call tracesSampler if it's defined" , ( ) => {
129
139
const tracesSampler = jest . fn ( ) ;
130
140
const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
@@ -154,6 +164,15 @@ describe('Hub', () => {
154
164
expect ( transaction . sampled ) . toBe ( true ) ;
155
165
} ) ;
156
166
167
+ it ( 'should set sampled = true if tracesSampler returns 1 (without global hub)' , ( ) => {
168
+ const tracesSampler = jest . fn ( ) . mockReturnValue ( 1 ) ;
169
+ const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
170
+ const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
171
+
172
+ expect ( tracesSampler ) . toHaveBeenCalled ( ) ;
173
+ expect ( transaction . sampled ) . toBe ( true ) ;
174
+ } ) ;
175
+
157
176
it ( 'should not try to override explicitly set positive sampling decision' , ( ) => {
158
177
// so that the decision otherwise would be false
159
178
const tracesSampler = jest . fn ( ) . mockReturnValue ( 0 ) ;
0 commit comments