@@ -623,4 +623,122 @@ describe('Tests Native Wrapper', () => {
623
623
expect ( NATIVE . stopProfiling ( ) ) . toBe ( null ) ;
624
624
} ) ;
625
625
} ) ;
626
+
627
+ describe ( 'setExtra' , ( ) => {
628
+ test ( 'passes string value to native method' , ( ) => {
629
+ NATIVE . setExtra ( 'key' , 'string value' ) ;
630
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , 'string value' ) ;
631
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
632
+ } ) ;
633
+
634
+ test ( 'stringifies number value before passing to native method' , ( ) => {
635
+ NATIVE . setExtra ( 'key' , 42 ) ;
636
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , '42' ) ;
637
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
638
+ } ) ;
639
+
640
+ test ( 'stringifies boolean value before passing to native method' , ( ) => {
641
+ NATIVE . setExtra ( 'key' , true ) ;
642
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , 'true' ) ;
643
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
644
+ } ) ;
645
+
646
+ test ( 'stringifies object value before passing to native method' , ( ) => {
647
+ const obj = { foo : 'bar' , baz : 123 } ;
648
+ NATIVE . setExtra ( 'key' , obj ) ;
649
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , JSON . stringify ( obj ) ) ;
650
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
651
+ } ) ;
652
+
653
+ test ( 'stringifies array value before passing to native method' , ( ) => {
654
+ const arr = [ 1 , 'two' , { three : 3 } ] ;
655
+ NATIVE . setExtra ( 'key' , arr ) ;
656
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , JSON . stringify ( arr ) ) ;
657
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
658
+ } ) ;
659
+
660
+ test ( 'handles null value by stringifying' , ( ) => {
661
+ NATIVE . setExtra ( 'key' , null ) ;
662
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , 'null' ) ;
663
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
664
+ } ) ;
665
+
666
+ test ( 'handles undefined value by stringifying' , ( ) => {
667
+ NATIVE . setExtra ( 'key' , undefined ) ;
668
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , 'undefined' ) ;
669
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
670
+ } ) ;
671
+
672
+ test ( 'handles non-serializable value by stringifying' , ( ) => {
673
+ const circular : { self ?: unknown } = { } ;
674
+ circular . self = circular ;
675
+ NATIVE . setExtra ( 'key' , circular ) ;
676
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledWith ( 'key' , '{"self":"[Circular ~]"}' ) ;
677
+ expect ( RNSentry . setExtra ) . toHaveBeenCalledOnce ( ) ;
678
+ } ) ;
679
+ } ) ;
680
+
681
+ describe ( 'setContext' , ( ) => {
682
+ test ( 'passes plain JS object to native method' , ( ) => {
683
+ const context = { foo : 'bar' , baz : 123 } ;
684
+ NATIVE . setContext ( 'key' , context ) ;
685
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , context ) ;
686
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
687
+ } ) ;
688
+
689
+ test ( 'converts non-plain JS object to plain object before passing to native method' , ( ) => {
690
+ class TestClass {
691
+ prop = 'value' ;
692
+ }
693
+ const context = new TestClass ( ) ;
694
+ NATIVE . setContext ( 'key' , context ) ;
695
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { prop : 'value' } ) ;
696
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
697
+ } ) ;
698
+
699
+ test ( 'converts array to object with "value" key before passing to native method' , ( ) => {
700
+ const context = [ 1 , 'two' , { three : 3 } ] ;
701
+ NATIVE . setContext ( 'key' , context ) ;
702
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { value : [ 1 , 'two' , { three : 3 } ] } ) ;
703
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
704
+ } ) ;
705
+
706
+ test ( 'converts string primitive to object with "value" key before passing to native method' , ( ) => {
707
+ NATIVE . setContext ( 'key' , 'string value' as unknown as object ) ;
708
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { value : 'string value' } ) ;
709
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
710
+ } ) ;
711
+
712
+ test ( 'converts number primitive to object with "value" key before passing to native method' , ( ) => {
713
+ NATIVE . setContext ( 'key' , 42 as unknown as object ) ;
714
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { value : 42 } ) ;
715
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
716
+ } ) ;
717
+
718
+ test ( 'converts boolean primitive to object with "value" key before passing to native method' , ( ) => {
719
+ NATIVE . setContext ( 'key' , true as unknown as object ) ;
720
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { value : true } ) ;
721
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
722
+ } ) ;
723
+
724
+ test ( 'handles null value by passing null to native method' , ( ) => {
725
+ NATIVE . setContext ( 'key' , null ) ;
726
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , null ) ;
727
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
728
+ } ) ;
729
+
730
+ test ( 'handles undefined value by converting to object with "value" key' , ( ) => {
731
+ NATIVE . setContext ( 'key' , undefined as unknown as object ) ;
732
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { value : undefined } ) ;
733
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
734
+ } ) ;
735
+
736
+ test ( 'handles non-serializable value by converting to normalized object' , ( ) => {
737
+ const circular : { self ?: unknown } = { } ;
738
+ circular . self = circular ;
739
+ NATIVE . setContext ( 'key' , circular ) ;
740
+ expect ( RNSentry . setContext ) . toHaveBeenCalledWith ( 'key' , { self : '[Circular ~]' } ) ;
741
+ expect ( RNSentry . setContext ) . toHaveBeenCalledOnce ( ) ;
742
+ } ) ;
743
+ } ) ;
626
744
} ) ;
0 commit comments