1- import { getClient } from '@sentry/core' ;
1+ import * as SentryCore from '@sentry/core' ;
22
3- jest . mock ( '@sentry/core' , ( ) => ( {
4- getClient : jest . fn ( ) ,
5- } ) ) ;
3+ import { enableSyncToNative } from '../../src/scopeSync' ;
64import { convertToNormalizedObject } from '../../src/utils/normalize' ;
5+ import { getDefaultTestClientOptions , TestClient } from '../mocks/client' ;
76
87describe ( 'normalize' , ( ) => {
9- describe ( 'convertToNormalizedObject' , ( ) => {
10- beforeEach ( ( ) => {
11- ( getClient as jest . Mock ) . mockReturnValue ( {
12- getOptions : jest . fn ( ) . mockReturnValue ( {
13- normalizeDepth : undefined ,
14- normalizeMaxBreadth : undefined ,
15- } ) ,
16- } ) ;
17- } ) ;
8+ afterEach ( ( ) => {
9+ jest . resetAllMocks ( ) ;
10+ } ) ;
1811
12+ describe ( 'convertToNormalizedObject' , ( ) => {
1913 test ( 'output equals input for normalized objects' , ( ) => {
2014 const actualResult = convertToNormalizedObject ( { foo : 'bar' } ) ;
2115 expect ( actualResult ) . toEqual ( { foo : 'bar' } ) ;
@@ -36,13 +30,23 @@ describe('normalize', () => {
3630 expect ( actualResult ) . toEqual ( { value : null } ) ;
3731 } ) ;
3832
33+ test ( 'converts array to an object' , ( ) => {
34+ const actualResult = convertToNormalizedObject ( [ ] ) ;
35+ expect ( actualResult ) . toEqual ( [ ] ) ;
36+ } ) ;
37+
38+ test ( 'converts custom class to an object' , ( ) => {
39+ class TestClass {
40+ test : string = 'foo' ;
41+ }
42+ const actualResult = convertToNormalizedObject ( new TestClass ( ) ) ;
43+ expect ( actualResult ) . toEqual ( { test : 'foo' } ) ;
44+ } ) ;
45+
3946 test ( 'respect normalizeDepth and normalizeMaxBreadth when set' , ( ) => {
40- ( getClient as jest . Mock ) . mockReturnValue ( {
41- getOptions : jest . fn ( ) . mockReturnValue ( {
42- normalizeDepth : 2 ,
43- normalizeMaxBreadth : 3 ,
44- } )
45- } ) ;
47+ SentryCore . setCurrentClient ( new TestClient ( getDefaultTestClientOptions ( { normalizeDepth : 2 , normalizeMaxBreadth : 3 } ) ) ) ;
48+ enableSyncToNative ( SentryCore . getIsolationScope ( ) ) ;
49+
4650 const obj = {
4751 key1 : '1' ,
4852 keyparent : {
0 commit comments