Skip to content

Commit f675c64

Browse files
authored
fix: Fix IE/Android request headers tests (#1171)
1 parent a278000 commit f675c64

File tree

1 file changed

+54
-25
lines changed

1 file changed

+54
-25
lines changed

test/raven.test.js

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,46 +1392,75 @@ describe('globals', function() {
13921392
});
13931393
});
13941394

1395-
it('should apply globalOptions.headers if specified', function() {
1396-
this.sinon.stub(Raven, 'isSetup').returns(true);
1397-
this.sinon.stub(window, 'fetch').resolves(true);
1395+
if (supportsFetch()) {
1396+
it('should apply globalOptions.headers with string value to fetch call if specified', function() {
1397+
this.sinon.stub(window, 'fetch').resolves(true);
13981398

1399-
Raven._globalProject = '2';
1400-
Raven._globalOptions = {
1401-
logger: 'javascript',
1402-
maxMessageLength: 100,
1403-
headers: {
1399+
Raven._globalProject = '2';
1400+
Raven._globalOptions = {
1401+
logger: 'javascript',
1402+
maxMessageLength: 100,
1403+
headers: {
1404+
'custom-header': 'value'
1405+
}
1406+
};
1407+
1408+
Raven._send({message: 'bar'});
1409+
1410+
assert.deepEqual(window.fetch.lastCall.args[1].headers, {
14041411
'custom-header': 'value'
1405-
}
1406-
};
1412+
});
1413+
});
14071414

1408-
Raven._send({message: 'bar'});
1415+
it('should apply globalOptions.headers with function value to fetch call if specified', function() {
1416+
this.sinon.stub(window, 'fetch').resolves(true);
1417+
1418+
Raven._globalProject = '2';
1419+
Raven._globalOptions = {
1420+
logger: 'javascript',
1421+
maxMessageLength: 100,
1422+
headers: {
1423+
'custom-header': function() {
1424+
return 'computed-header-value';
1425+
}
1426+
}
1427+
};
1428+
1429+
Raven._send({message: 'bar'});
14091430

1410-
assert.deepEqual(window.fetch.lastCall.args[1].headers, {
1411-
'custom-header': 'value'
1431+
assert.deepEqual(window.fetch.lastCall.args[1].headers, {
1432+
'custom-header': 'computed-header-value'
1433+
});
14121434
});
1413-
});
1435+
}
14141436

1415-
it('should apply globalOptions.headers with function value if specified', function() {
1416-
this.sinon.stub(Raven, 'isSetup').returns(true);
1417-
this.sinon.stub(window, 'fetch').resolves(true);
1437+
it('should apply globalOptions.headers with string or function value to XHR call if specified', function() {
1438+
var origFetch = window.fetch;
1439+
delete window.fetch;
1440+
1441+
var requests = [];
1442+
var xhr = sinon.useFakeXMLHttpRequest();
1443+
1444+
xhr.onCreate = function(xhr) {
1445+
requests.push(xhr);
1446+
};
14181447

1419-
Raven._globalProject = '2';
14201448
Raven._globalOptions = {
1421-
logger: 'javascript',
1422-
maxMessageLength: 100,
14231449
headers: {
1424-
'custom-header': function() {
1425-
return 'computed-header-value';
1450+
'custom-string-header': 'pickle-rick',
1451+
'custom-function-header': function() {
1452+
return 'morty';
14261453
}
14271454
}
14281455
};
14291456

14301457
Raven._send({message: 'bar'});
14311458

1432-
assert.deepEqual(window.fetch.lastCall.args[1].headers, {
1433-
'custom-header': 'computed-header-value'
1434-
});
1459+
var lastXhr = requests[requests.length - 1];
1460+
assert.equal(lastXhr.HEADERS_RECEIVED, 2);
1461+
1462+
window.fetch = origFetch;
1463+
xhr.restore();
14351464
});
14361465

14371466
it('should check `Raven.isSetup`', function() {

0 commit comments

Comments
 (0)