@@ -25,6 +25,7 @@ var joinRegExp = utils.joinRegExp;
25
25
var supportsErrorEvent = utils . supportsErrorEvent ;
26
26
var supportsFetch = utils . supportsFetch ;
27
27
var supportsReferrerPolicy = utils . supportsReferrerPolicy ;
28
+ var supportsPromiseRejectionEvent = utils . supportsPromiseRejectionEvent ;
28
29
29
30
// window.console must be stubbed in for browsers that don't have it
30
31
if ( typeof window . console === 'undefined' ) {
@@ -756,6 +757,40 @@ describe('globals', function() {
756
757
} ) ;
757
758
} ) ;
758
759
760
+ if ( supportsPromiseRejectionEvent ( ) ) {
761
+ describe ( 'captureUnhandledRejections' , function ( ) {
762
+ it ( 'should capture string rejections' , function ( done ) {
763
+ Raven . _attachPromiseRejectionHandler ( ) ;
764
+
765
+ this . sinon . stub ( Raven , 'captureException' ) . callsFake ( function ( reason ) {
766
+ assert . equal ( reason , 'foo' ) ;
767
+ Raven . _detachPromiseRejectionHandler ( ) ;
768
+ done ( ) ;
769
+ } ) ;
770
+
771
+ new Promise ( function ( resolve , reject ) {
772
+ reject ( 'foo' ) ;
773
+ } ) ;
774
+ } ) ;
775
+
776
+ it ( 'should capture error rejections' , function ( done ) {
777
+ var err = new Error ( 'foo' ) ;
778
+
779
+ Raven . _attachPromiseRejectionHandler ( ) ;
780
+
781
+ this . sinon . stub ( Raven , 'captureException' ) . callsFake ( function ( reason ) {
782
+ assert . equal ( reason , err ) ;
783
+ Raven . _detachPromiseRejectionHandler ( ) ;
784
+ done ( ) ;
785
+ } ) ;
786
+
787
+ new Promise ( function ( resolve , reject ) {
788
+ reject ( err ) ;
789
+ } ) ;
790
+ } ) ;
791
+ } ) ;
792
+ }
793
+
759
794
describe ( 'send' , function ( ) {
760
795
it ( 'should build a good data payload' , function ( ) {
761
796
this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
@@ -2347,6 +2382,29 @@ describe('Raven (public API)', function() {
2347
2382
} ) ;
2348
2383
} ) ;
2349
2384
2385
+ describe ( 'captureUnhandledRejections' , function ( ) {
2386
+ it ( 'should be true by default' , function ( ) {
2387
+ Raven . config ( SENTRY_DSN ) ;
2388
+ assert . isTrue ( Raven . _globalOptions . captureUnhandledRejections ) ;
2389
+ } ) ;
2390
+
2391
+ it ( 'should be true if set to true' , function ( ) {
2392
+ Raven . config ( SENTRY_DSN , {
2393
+ captureUnhandledRejections : true
2394
+ } ) ;
2395
+
2396
+ assert . isTrue ( Raven . _globalOptions . captureUnhandledRejections ) ;
2397
+ } ) ;
2398
+
2399
+ it ( 'should be false if set to false' , function ( ) {
2400
+ Raven . config ( SENTRY_DSN , {
2401
+ captureUnhandledRejections : false
2402
+ } ) ;
2403
+
2404
+ assert . isFalse ( Raven . _globalOptions . captureUnhandledRejections ) ;
2405
+ } ) ;
2406
+ } ) ;
2407
+
2350
2408
describe ( 'maxBreadcrumbs' , function ( ) {
2351
2409
it ( 'should override the default' , function ( ) {
2352
2410
Raven . config ( SENTRY_DSN , { maxBreadcrumbs : 50 } ) ;
0 commit comments