Skip to content

Commit 52a4f19

Browse files
committed
Add some basic tests for deferred wrapping
1 parent 27914b5 commit 52a4f19

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

test/plugins/jquery.test.js

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// TODO(dcramer): need some kind of clean setup state and dynamic
2+
// loading of the jquery plugin
13
describe('jQuery', function(){
24
describe('.fn.ready', function(){
35
it('captures exceptions #integration', function(){
46
var err = new Error('foo');
5-
this.sinon.stub(Raven, 'captureException')
7+
this.sinon.stub(Raven, 'captureException');
68
try {
79
jQuery(function(){
810
throw err;
@@ -14,4 +16,69 @@ describe('jQuery', function(){
1416
assert.equal(Raven.captureException.lastCall.args[0], err);
1517
});
1618
});
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+
});
1784
});

0 commit comments

Comments
 (0)