@@ -25,6 +25,7 @@ var joinRegExp = utils.joinRegExp;
2525var supportsErrorEvent = utils . supportsErrorEvent ;
2626var supportsFetch = utils . supportsFetch ;
2727var supportsReferrerPolicy = utils . supportsReferrerPolicy ;
28+ var supportsPromiseRejectionEvent = utils . supportsPromiseRejectionEvent ;
2829
2930// window.console must be stubbed in for browsers that don't have it
3031if ( typeof window . console === 'undefined' ) {
@@ -756,6 +757,40 @@ describe('globals', function() {
756757 } ) ;
757758 } ) ;
758759
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+
759794 describe ( 'send' , function ( ) {
760795 it ( 'should build a good data payload' , function ( ) {
761796 this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
@@ -2347,6 +2382,29 @@ describe('Raven (public API)', function() {
23472382 } ) ;
23482383 } ) ;
23492384
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+
23502408 describe ( 'maxBreadcrumbs' , function ( ) {
23512409 it ( 'should override the default' , function ( ) {
23522410 Raven . config ( SENTRY_DSN , { maxBreadcrumbs : 50 } ) ;
0 commit comments