@@ -6,6 +6,21 @@ var majorVersion = parseInt(versionRegexp.exec(process.version)[1], 10);
6
6
7
7
var raven = require ( '../' ) ;
8
8
9
+ var _oldConsoleWarn = console . warn ;
10
+
11
+ function mockConsoleWarn ( ) {
12
+ console . warn = function ( ) {
13
+ console . warn . _called = true ;
14
+ ++ console . warn . _callCount ;
15
+ } ;
16
+ console . warn . _called = false ;
17
+ console . warn . _callCount = 0 ;
18
+ }
19
+
20
+ function restoreConsoleWarn ( ) {
21
+ console . warn = _oldConsoleWarn ;
22
+ }
23
+
9
24
describe ( 'raven.utils' , function ( ) {
10
25
describe ( '#parseDSN()' , function ( ) {
11
26
it ( 'should parse hosted Sentry DSN without path' , function ( ) {
@@ -599,4 +614,57 @@ describe('raven.utils', function() {
599
614
}
600
615
} ) ;
601
616
} ) ;
617
+
618
+ describe ( '#consoleAlert()' , function ( ) {
619
+ it ( 'should call console.warn if enabled' , function ( ) {
620
+ mockConsoleWarn ( ) ;
621
+ raven . utils . consoleAlert ( 'foo' ) ;
622
+ raven . utils . consoleAlert ( 'foo' ) ;
623
+ console . warn . _called . should . eql ( true ) ;
624
+ console . warn . _callCount . should . eql ( 2 ) ;
625
+ restoreConsoleWarn ( ) ;
626
+ } ) ;
627
+
628
+ it ( 'should be disabled after calling disableConsoleAlerts' , function ( ) {
629
+ mockConsoleWarn ( ) ;
630
+ raven . utils . disableConsoleAlerts ( ) ;
631
+ raven . utils . consoleAlert ( 'foo' ) ;
632
+ console . warn . _called . should . eql ( false ) ;
633
+ console . warn . _callCount . should . eql ( 0 ) ;
634
+ raven . utils . enableConsoleAlerts ( ) ;
635
+ restoreConsoleWarn ( ) ;
636
+ } ) ;
637
+
638
+ it ( 'should be disabled after calling disableConsoleAlerts, even after previous successful calls' , function ( ) {
639
+ mockConsoleWarn ( ) ;
640
+ raven . utils . consoleAlert ( 'foo' ) ;
641
+ console . warn . _called . should . eql ( true ) ;
642
+ console . warn . _callCount . should . eql ( 1 ) ;
643
+ raven . utils . disableConsoleAlerts ( ) ;
644
+ raven . utils . consoleAlert ( 'foo' ) ;
645
+ console . warn . _callCount . should . eql ( 1 ) ;
646
+ raven . utils . enableConsoleAlerts ( ) ;
647
+ restoreConsoleWarn ( ) ;
648
+ } ) ;
649
+ } ) ;
650
+
651
+ describe ( '#consoleAlertOnce()' , function ( ) {
652
+ it ( 'should call console.warn if enabled, but only once with the same message' , function ( ) {
653
+ mockConsoleWarn ( ) ;
654
+ raven . utils . consoleAlertOnce ( 'foo' ) ;
655
+ console . warn . _called . should . eql ( true ) ;
656
+ console . warn . _callCount . should . eql ( 1 ) ;
657
+ raven . utils . consoleAlertOnce ( 'foo' ) ;
658
+ console . warn . _callCount . should . eql ( 1 ) ;
659
+ restoreConsoleWarn ( ) ;
660
+ } ) ;
661
+
662
+ it ( 'should be disable after calling disableConsoleAlerts' , function ( ) {
663
+ mockConsoleWarn ( ) ;
664
+ raven . utils . disableConsoleAlerts ( ) ;
665
+ raven . utils . consoleAlertOnce ( 'foo' ) ;
666
+ console . warn . _called . should . eql ( false ) ;
667
+ console . warn . _callCount . should . eql ( 0 ) ;
668
+ raven . utils . enableConsoleAlerts ( ) ;
669
+ restoreConsoleWarn ( ) ;
602
670
} ) ;
0 commit comments