Skip to content

test(res.redirect): add tests for argument deprecation warnings - #7590

Closed
Gustavo-Luiz2304 wants to merge 1 commit into
expressjs:masterfrom
Gustavo-Luiz2304:test/redirect-deprecations
Closed

Gustavo-Luiz2304 wants to merge 1 commit into
expressjs:masterfrom
Gustavo-Luiz2304:test/redirect-deprecations

Conversation

@Gustavo-Luiz2304

Copy link
Copy Markdown

Summary

#6405 added deprecation warnings to res.redirect() for a missing/non-string url and a non-number status, but no tests cover them. This PR adds those tests.

Tests only. Nothing in lib/ changes.

Details

test/support/env.js silences express deprecations through NO_DEPRECATION. depd still emits the deprecation event on process when a listener is attached, so the new tests listen for that event and check which messages were emitted:

  • res.redirect() → Provide a url argument, Url must be a string
  • res.redirect(301, undefined) → Provide a url argument, Url must be a string
  • res.redirect(301, 42) → Url must be a string
  • res.redirect('301', url) → Status must be a number
  • valid arguments → no warnings

I checked that the tests fail when one of the deprecate() calls is removed. npm test and npm run lint pass.

Related

Refs #6941. This does not close it. Changing res.redirect() to throw for invalid arguments is the semver-major change in #6404 (6.x). This PR just covers the current 5.x deprecation behavior with tests until then.

🤖 Generated with Claude Code

The deprecation warnings added in expressjs#6405 for missing/non-string url
and non-number status had no test coverage. Listen for the depd
'deprecation' event to assert which warnings are emitted.

Refs: expressjs#6941

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@krzysdz

krzysdz commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #7571

@krzysdz krzysdz marked this as a duplicate of #7571 Nov 8, 2026
@krzysdz krzysdz closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants