Skip to content
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

[v4] Deprecate res.clearCookie accepting options.maxAge and options.expires #5672

Merged
Prev Previous commit
Next Next commit
add tests to codify deprecated behavior
  • Loading branch information
jonchurch committed May 26, 2024
commit 6c76c0cdc0d128a42590ec0a1de35ef94fc22705
30 changes: 30 additions & 0 deletions test/res.clearCookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,35 @@ describe('res', function(){
.expect('Set-Cookie', 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT')
.expect(200, done)
})

it('should set expires when passed', function(done) {
var expiresAt = new Date()
var app = express();

app.use(function(req, res){
res.clearCookie('sid', { expires: expiresAt }).end();
});

request(app)
.get('/')
.expect('Set-Cookie', 'sid=; Path=/; Expires=' + expiresAt.toUTCString() )
.expect(200, done)
})

it('should set maxAge when passed', function(done) {
var maxAgeInMs = 10000
var expiresAt = new Date()
var expectedExpires = new Date(expiresAt.getTime() + maxAgeInMs)
var app = express();

app.use(function(req, res){
res.clearCookie('sid', { expires: expiresAt, maxAge: maxAgeInMs }).end();
});

request(app)
.get('/')
.expect('Set-Cookie', 'sid=; Max-Age=10; Path=/; Expires=' + expectedExpires.toUTCString())
.expect(200, done)
})
})
})