|
1 | 1 | 'use strict' |
2 | 2 |
|
| 3 | +var assert = require('node:assert'); |
3 | 4 | var express = require('..'); |
4 | 5 | var request = require('supertest'); |
5 | 6 | var utils = require('./support/utils'); |
@@ -211,4 +212,80 @@ describe('res', function(){ |
211 | 212 | .end(done) |
212 | 213 | }) |
213 | 214 | }) |
| 215 | + |
| 216 | + // Note: depd reports deprecations once per call site; keep separate res.redirect() calls. |
| 217 | + describe('when arguments are omitted or invalid', function () { |
| 218 | + it('should emit deprecation when url is missing', function (done) { |
| 219 | + var app = express(); |
| 220 | + var warnings = []; |
| 221 | + function onDeprecation(err) { |
| 222 | + warnings.push(err.message); |
| 223 | + } |
| 224 | + process.on('deprecation', onDeprecation); |
| 225 | + |
| 226 | + app.use(function (req, res) { |
| 227 | + res.redirect(); |
| 228 | + res.end(); |
| 229 | + }); |
| 230 | + |
| 231 | + request(app) |
| 232 | + .get('/') |
| 233 | + .expect(302) |
| 234 | + .end(function (err) { |
| 235 | + process.removeListener('deprecation', onDeprecation); |
| 236 | + if (err) return done(err); |
| 237 | + assert.deepStrictEqual(warnings, ['Provide a url argument', 'Url must be a string']); |
| 238 | + done(); |
| 239 | + }); |
| 240 | + }) |
| 241 | + |
| 242 | + it('should emit deprecation when url is not a string', function (done) { |
| 243 | + var app = express(); |
| 244 | + var warnings = []; |
| 245 | + function onDeprecation(err) { |
| 246 | + warnings.push(err.message); |
| 247 | + } |
| 248 | + process.on('deprecation', onDeprecation); |
| 249 | + |
| 250 | + app.use(function (req, res) { |
| 251 | + res.redirect(302, 12345); |
| 252 | + res.end(); |
| 253 | + }); |
| 254 | + |
| 255 | + request(app) |
| 256 | + .get('/') |
| 257 | + .expect(302) |
| 258 | + .end(function (err) { |
| 259 | + process.removeListener('deprecation', onDeprecation); |
| 260 | + if (err) return done(err); |
| 261 | + assert.deepStrictEqual(warnings, ['Url must be a string']); |
| 262 | + done(); |
| 263 | + }); |
| 264 | + }) |
| 265 | + |
| 266 | + it('should emit deprecation when status is not a number', function (done) { |
| 267 | + var app = express(); |
| 268 | + var warnings = []; |
| 269 | + function onDeprecation(err) { |
| 270 | + warnings.push(err.message); |
| 271 | + } |
| 272 | + process.on('deprecation', onDeprecation); |
| 273 | + |
| 274 | + app.use(function (req, res) { |
| 275 | + assert.throws(function () { |
| 276 | + res.redirect('301', 'http://google.com'); |
| 277 | + }, TypeError); |
| 278 | + res.end(); |
| 279 | + }); |
| 280 | + |
| 281 | + request(app) |
| 282 | + .get('/') |
| 283 | + .end(function (err) { |
| 284 | + process.removeListener('deprecation', onDeprecation); |
| 285 | + if (err) return done(err); |
| 286 | + assert.deepStrictEqual(warnings, ['Status must be a number']); |
| 287 | + done(); |
| 288 | + }); |
| 289 | + }) |
| 290 | + }) |
214 | 291 | }) |
0 commit comments