Skip to content

fix: Fix IE/Android request headers tests #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 54 additions & 25 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,46 +1392,75 @@ describe('globals', function() {
});
});

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

Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100,
headers: {
Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100,
headers: {
'custom-header': 'value'
}
};

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

assert.deepEqual(window.fetch.lastCall.args[1].headers, {
'custom-header': 'value'
}
};
});
});

Raven._send({message: 'bar'});
it('should apply globalOptions.headers with function value to fetch call if specified', function() {
this.sinon.stub(window, 'fetch').resolves(true);

Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100,
headers: {
'custom-header': function() {
return 'computed-header-value';
}
}
};

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

assert.deepEqual(window.fetch.lastCall.args[1].headers, {
'custom-header': 'value'
assert.deepEqual(window.fetch.lastCall.args[1].headers, {
'custom-header': 'computed-header-value'
});
});
});
}

it('should apply globalOptions.headers with function value if specified', function() {
this.sinon.stub(Raven, 'isSetup').returns(true);
this.sinon.stub(window, 'fetch').resolves(true);
it('should apply globalOptions.headers with string or function value to XHR call if specified', function() {
var origFetch = window.fetch;
delete window.fetch;

var requests = [];
var xhr = sinon.useFakeXMLHttpRequest();

xhr.onCreate = function(xhr) {
requests.push(xhr);
};

Raven._globalProject = '2';
Raven._globalOptions = {
logger: 'javascript',
maxMessageLength: 100,
headers: {
'custom-header': function() {
return 'computed-header-value';
'custom-string-header': 'pickle-rick',
'custom-function-header': function() {
return 'morty';
}
}
};

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

assert.deepEqual(window.fetch.lastCall.args[1].headers, {
'custom-header': 'computed-header-value'
});
var lastXhr = requests[requests.length - 1];
assert.equal(lastXhr.HEADERS_RECEIVED, 2);

window.fetch = origFetch;
xhr.restore();
});

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