Unit test cases for uncovered lines for response.js file#7105
Unit test cases for uncovered lines for response.js file#7105ashish3011 wants to merge 6 commits intoexpressjs:masterfrom
Conversation
| it('should deprecate when redirect called without a url', function (done) { | ||
| var app = express() | ||
|
|
||
| app.use(function (req, res) { | ||
| res.redirect('') | ||
| }) | ||
|
|
||
| request(app) | ||
| .get('/') | ||
| .expect(302) | ||
| .expect('Location', '') | ||
| .expect(/Redirecting to/, done) | ||
| }) | ||
|
|
||
| it('should deprecate when redirect address is not a string', function (done) { | ||
| var app = express() | ||
|
|
||
| app.use(function (req, res) { | ||
| res.redirect(302, 123) | ||
| }) | ||
|
|
||
| request(app) | ||
| .get('/') | ||
| .expect(302) | ||
| .expect('Location', '123') | ||
| .expect(/Redirecting to 123/, done) | ||
| }) |
There was a problem hiding this comment.
How are you checking here for a deprecation warning? I don't see any code that would verify if there is a warning. These tests would also pass without #6405.
There was a problem hiding this comment.
Thanks for the feedback!
You're correct that the tests only verify the deprecated behaviour, not the warnings themselves. However, since deprecation warnings for Express are suppressed in the test environment via [NO_DEPRECATION](to avoid noise), the tests focus on ensuring the deprecated code paths are executed, which is confirmed by coverage reports showing lines 824, 828, and 832 in lib/response.js are hit.
The tests would indeed pass without the deprecation calls if the behaviour remained the same, but since the goal is coverage, these tests ensure the deprecation logic runs. If you'd like explicit warning checks, we could modify the test environment to enable them, but that might introduce noise in CI. Let me know if you'd prefer that approach!
The changes ensure the targeted lines are covered while maintaining test stability.
There was a problem hiding this comment.
Just "covering" some lines without checking if they do what they are supposed to do does not make sense in my opinion.
The tests are named "should deprecate", so I consider not checking this behaviour a problem.
Unit test cases for uncovered lines for response.js file