1
+ // TODO(dcramer): need some kind of clean setup state and dynamic
2
+ // loading of the jquery plugin
1
3
describe ( 'jQuery' , function ( ) {
2
4
describe ( '.fn.ready' , function ( ) {
3
5
it ( 'captures exceptions #integration' , function ( ) {
4
6
var err = new Error ( 'foo' ) ;
5
- this . sinon . stub ( Raven , 'captureException' )
7
+ this . sinon . stub ( Raven , 'captureException' ) ;
6
8
try {
7
9
jQuery ( function ( ) {
8
10
throw err ;
@@ -14,4 +16,69 @@ describe('jQuery', function(){
14
16
assert . equal ( Raven . captureException . lastCall . args [ 0 ] , err ) ;
15
17
} ) ;
16
18
} ) ;
19
+
20
+ describe ( '.Deferred' , function ( ) {
21
+ var err ;
22
+
23
+ // testing $.Deferred's promises
24
+ var deferredPromises = {
25
+ done : 'resolve' ,
26
+ then : 'resolve' ,
27
+ fail : 'reject' ,
28
+ always : 'reject' ,
29
+ progress : 'notify' // since 1.7
30
+ } ;
31
+
32
+ // testing $.Deferred's promises with resolveWith, rejectWith and notifyWith
33
+ var deferredPromisesWith = {
34
+ done : 'resolveWith' ,
35
+ then : 'resolveWith' ,
36
+ fail : 'rejectWith' ,
37
+ always : 'resolveWith' ,
38
+ progress : 'notifyWith' // since 1.7
39
+ } ;
40
+
41
+ var assertErrorRecorded = function ( func ) {
42
+ try {
43
+ func ( ) ;
44
+ } catch ( exc1 ) {
45
+ if ( exc1 !== err ) throw exc1 ;
46
+ }
47
+ assert . isTrue ( Raven . captureException . called ) ;
48
+ assert . equal ( Raven . captureException . lastCall . args [ 0 ] , err ) ;
49
+ } ;
50
+
51
+ beforeEach ( function ( ) {
52
+ err = new Error ( 'foo' ) ;
53
+ this . sinon . stub ( Raven , 'captureException' ) ;
54
+ } ) ;
55
+
56
+ for ( var key in deferredPromises ) {
57
+ it ( 'captures errors from ' + key , function ( key ) {
58
+ return function ( ) {
59
+ assertErrorRecorded ( function ( ) {
60
+ var dfd = jQuery . Deferred ( ) ;
61
+ dfd . promise ( ) [ key ] ( function ( ) {
62
+ throw err ;
63
+ } ) ;
64
+ dfd [ deferredPromises [ key ] ] ( ) ;
65
+ } ) ;
66
+ } ;
67
+ } ( key ) ) ;
68
+ }
69
+
70
+ for ( var key in deferredPromisesWith ) {
71
+ it ( 'captures errors from ' + key + ' with context' , function ( key ) {
72
+ return function ( ) {
73
+ assertErrorRecorded ( function ( ) {
74
+ var dfd = $ . Deferred ( ) ;
75
+ dfd . promise ( ) [ key ] ( function ( ) {
76
+ throw err ;
77
+ } ) ;
78
+ dfd [ deferredPromisesWith [ key ] ] ( dfd ) ;
79
+ } ) ;
80
+ } ;
81
+ } ( key ) ) ;
82
+ }
83
+ } ) ;
17
84
} ) ;
0 commit comments