Skip to content

Commit 01a180f

Browse files
committed
test: Run ErrorEvent tests only when its available
1 parent 6746dfd commit 01a180f

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function isError(value) {
2323
}
2424

2525
function isErrorEvent(value) {
26-
return {}.toString.call(value) === '[object ErrorEvent]';
26+
return supportsErrorEvent() && {}.toString.call(value) === '[object ErrorEvent]';
2727
}
2828

2929
function isUndefined(what) {
@@ -43,6 +43,15 @@ function isEmptyObject(what) {
4343
return true;
4444
}
4545

46+
function supportsErrorEvent() {
47+
try {
48+
new ErrorEvent(''); // eslint-disable-line no-new
49+
return true;
50+
} catch (e) {
51+
return false;
52+
}
53+
}
54+
4655
function wrappedCallback(callback) {
4756
function dataCallback(data, original) {
4857
var normalizedData = callback(data) || data;
@@ -357,6 +366,7 @@ module.exports = {
357366
isFunction: isFunction,
358367
isString: isString,
359368
isEmptyObject: isEmptyObject,
369+
supportsErrorEvent: supportsErrorEvent,
360370
wrappedCallback: wrappedCallback,
361371
each: each,
362372
objectMerge: objectMerge,

test/raven.test.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ _Raven.prototype._getUuid = function() {
2020
return 'abc123';
2121
};
2222

23-
var joinRegExp = require('../src/utils').joinRegExp;
23+
var utils = require('../src/utils');
24+
var joinRegExp = utils.joinRegExp;
25+
var supportsErrorEvent = utils.supportsErrorEvent;
2426

2527
// window.console must be stubbed in for browsers that don't have it
2628
if (typeof window.console === 'undefined') {
@@ -2770,21 +2772,23 @@ describe('Raven (public API)', function() {
27702772
});
27712773

27722774
describe('.captureException', function() {
2773-
it('should treat ErrorEvents similarly to Errors', function() {
2774-
var error = new ErrorEvent('pickleRick', {error: new Error('pickleRick')});
2775-
this.sinon.stub(Raven, 'isSetup').returns(true);
2776-
this.sinon.stub(Raven, '_handleStackInfo');
2777-
Raven.captureException(error, {foo: 'bar'});
2778-
assert.isTrue(Raven._handleStackInfo.calledOnce);
2779-
});
2775+
if (supportsErrorEvent()) {
2776+
it('should treat ErrorEvents similarly to Errors', function() {
2777+
var error = new ErrorEvent('pickleRick', {error: new Error('pickleRick')});
2778+
this.sinon.stub(Raven, 'isSetup').returns(true);
2779+
this.sinon.stub(Raven, '_handleStackInfo');
2780+
Raven.captureException(error, {foo: 'bar'});
2781+
assert.isTrue(Raven._handleStackInfo.calledOnce);
2782+
});
27802783

2781-
it('should send ErrorEvents without Errors as messages', function() {
2782-
var error = new ErrorEvent('pickleRick');
2783-
this.sinon.stub(Raven, 'isSetup').returns(true);
2784-
this.sinon.stub(Raven, 'captureMessage');
2785-
Raven.captureException(error, {foo: 'bar'});
2786-
assert.isTrue(Raven.captureMessage.calledOnce);
2787-
});
2784+
it('should send ErrorEvents without Errors as messages', function() {
2785+
var error = new ErrorEvent('pickleRick');
2786+
this.sinon.stub(Raven, 'isSetup').returns(true);
2787+
this.sinon.stub(Raven, 'captureMessage');
2788+
Raven.captureException(error, {foo: 'bar'});
2789+
assert.isTrue(Raven.captureMessage.calledOnce);
2790+
});
2791+
}
27882792

27892793
it('should send non-Errors as messages', function() {
27902794
this.sinon.stub(Raven, 'isSetup').returns(true);

test/utils.test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var isObject = utils.isObject;
1212
var isEmptyObject = utils.isEmptyObject;
1313
var isError = utils.isError;
1414
var isErrorEvent = utils.isErrorEvent;
15+
var supportsErrorEvent = utils.supportsErrorEvent;
1516
var wrappedCallback = utils.wrappedCallback;
1617
var joinRegExp = utils.joinRegExp;
1718
var objectMerge = utils.objectMerge;
@@ -66,12 +67,14 @@ describe('utils', function() {
6667
});
6768
});
6869

69-
describe('isErrorEvent', function() {
70-
it('should work as advertised', function() {
71-
assert.isFalse(isErrorEvent(new Error()));
72-
assert.isTrue(isErrorEvent(new ErrorEvent('')));
70+
if (supportsErrorEvent()) {
71+
describe('isErrorEvent', function() {
72+
it('should work as advertised', function() {
73+
assert.isFalse(isErrorEvent(new Error()));
74+
assert.isTrue(isErrorEvent(new ErrorEvent('')));
75+
});
7376
});
74-
});
77+
}
7578

7679
describe('isError', function() {
7780
function testErrorFromDifferentContext(createError) {

0 commit comments

Comments
 (0)