@@ -11,6 +11,7 @@ import {
1111} from '../../src/browser/browsertracing' ;
1212import { defaultRequestInstrumentionOptions } from '../../src/browser/request' ;
1313import { defaultRoutingInstrumentation } from '../../src/browser/router' ;
14+ import * as hubExtensions from '../../src/hubextensions' ;
1415import { DEFAULT_IDLE_TIMEOUT , IdleTransaction } from '../../src/idletransaction' ;
1516import { getActiveTransaction , secToMs } from '../../src/utils' ;
1617
@@ -209,12 +210,26 @@ describe('BrowserTracing', () => {
209210 const name = 'sentry-trace' ;
210211 const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
211212 document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
213+ const startIdleTransaction = jest . spyOn ( hubExtensions , 'startIdleTransaction' ) ;
214+
212215 createBrowserTracing ( true , { routingInstrumentation : customRoutingInstrumentation } ) ;
213- const transaction = getActiveTransaction ( hub ) as IdleTransaction ;
214216
215- expect ( transaction . traceId ) . toBe ( '126de09502ae4e0fb26c6967190756a4' ) ;
216- expect ( transaction . parentSpanId ) . toBe ( 'b6e54397b12a2a0f' ) ;
217- expect ( transaction . sampled ) . toBe ( true ) ;
217+ // we match on the calls themselves (rather than calling .toHaveBeenCalledWith()) because that method requires all
218+ // of the arguments be supplied, when we really only care about the transaction context which gets passed
219+ expect ( startIdleTransaction . mock . calls ) . toEqual (
220+ // all calls
221+ expect . arrayContaining ( [
222+ // all arguments
223+ expect . arrayContaining ( [
224+ // one of the arguments
225+ expect . objectContaining ( {
226+ traceId : '126de09502ae4e0fb26c6967190756a4' ,
227+ parentSpanId : 'b6e54397b12a2a0f' ,
228+ parentSampled : true ,
229+ } ) ,
230+ ] ) ,
231+ ] ) ,
232+ ) ;
218233 } ) ;
219234
220235 describe ( 'idleTimeout' , ( ) => {
@@ -342,20 +357,24 @@ describe('BrowserTracing', () => {
342357 } ) ;
343358} ) ;
344359
345- describe ( 'getMeta' , ( ) => {
346- it ( 'returns a found meta tag contents' , ( ) => {
347- const name = 'sentry-trace' ;
348- const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
349- document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
360+ describe ( 'sentry-trace <meta> element' , ( ) => {
361+ describe ( 'getMetaContent' , ( ) => {
362+ it ( 'finds the specified tag and extracts the value' , ( ) => {
363+ const name = 'sentry-trace' ;
364+ const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1' ;
365+ document . head . innerHTML = `<meta name="${ name } " content="${ content } ">` ;
350366
351- const meta = getMetaContent ( name ) ;
352- expect ( meta ) . toBe ( content ) ;
353- } ) ;
367+ const metaTagValue = getMetaContent ( name ) ;
368+ expect ( metaTagValue ) . toBe ( content ) ;
369+ } ) ;
354370
355- it ( 'only returns meta tags queried for' , ( ) => {
356- document . head . innerHTML = `<meta name="not-test ">` ;
371+ it ( "doesn't return meta tags other than the one specified" , ( ) => {
372+ document . head . innerHTML = `<meta name="cat-cafe ">` ;
357373
358- const meta = getMetaContent ( 'test' ) ;
359- expect ( meta ) . toBe ( null ) ;
374+ const metaTagValue = getMetaContent ( 'dogpark' ) ;
375+ expect ( metaTagValue ) . toBe ( null ) ;
376+ } ) ;
377+
378+ } ) ;
360379 } ) ;
361380} ) ;
0 commit comments