File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
1
import type { BrowserOptions } from '@sentry/browser' ;
2
- import { init as browserInit } from '@sentry/browser' ;
2
+ import { init as browserInit , setContext } from '@sentry/browser' ;
3
3
import { applySdkMetadata } from '@sentry/core' ;
4
4
5
+ import { version } from 'react' ;
6
+
5
7
/**
6
8
* Inits the React SDK
7
9
*/
@@ -11,6 +13,6 @@ export function init(options: BrowserOptions): void {
11
13
} ;
12
14
13
15
applySdkMetadata ( opts , 'react' ) ;
14
-
16
+ setContext ( 'react' , { version } ) ;
15
17
browserInit ( opts ) ;
16
18
}
Original file line number Diff line number Diff line change
1
+ import * as SentryBrowser from '@sentry/browser' ;
2
+ import { version } from 'react' ;
3
+ import { init } from '../src/sdk' ;
4
+
5
+ describe ( 'init' , ( ) => {
6
+ it ( 'sets the React version (if available) in the global scope' , ( ) => {
7
+ const setContextSpy = jest . spyOn ( SentryBrowser , 'setContext' ) ;
8
+
9
+ init ( { } ) ;
10
+
11
+ // In our case, the Angular version is 10 because that's the version we use for compilation
12
+ // (and hence the dependency version of Angular core we installed (see package.json))
13
+ expect ( setContextSpy ) . toHaveBeenCalledTimes ( 1 ) ;
14
+ expect ( setContextSpy ) . toHaveBeenCalledWith ( 'react' , { version } ) ;
15
+ } ) ;
16
+ } ) ;
You can’t perform that action at this time.
0 commit comments