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