Skip to content

Commit

Permalink
Override superagent's _saveCookies method to fix jest weird set-cooki…
Browse files Browse the repository at this point in the history
…e behavior

See ladjs#413 and jestjs/jest#3547
  • Loading branch information
crux153 committed Mar 11, 2018
1 parent 003c7f6 commit a540698
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ function TestAgent(app, options) {

TestAgent.prototype.__proto__ = Agent.prototype;

/**
* Override superagent's _saveCookies method
* to fix jest weird set-cookie behavior
* (https://github.com/facebook/jest/issues/3547)
*
* @param {Response} res
* @api private
*/
TestAgent.prototype._saveCookies = function(res) {
var cookies = res.headers['set-cookie'];
if (cookies) {
cookies = cookies.reduce(function(cookies, cookie) {
return cookies.concat(cookie.split(/,(?!\s)/));
}, []);
this.jar.setCookies(cookies);
}
};

// override HTTP verb methods
methods.forEach(function(method) {
TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars
Expand Down

0 comments on commit a540698

Please sign in to comment.