Skip to content

test: add unit tests for res.contentType alias and parameters in res.type#7339

Open
thePranav-kpk wants to merge 1 commit into
expressjs:masterfrom
thePranav-kpk:test/res-type-tests
Open

test: add unit tests for res.contentType alias and parameters in res.type#7339
thePranav-kpk wants to merge 1 commit into
expressjs:masterfrom
thePranav-kpk:test/res-type-tests

Conversation

@thePranav-kpk

Copy link
Copy Markdown

Description

This PR adds explicit unit test coverage for:

  1. The res.contentType(str) alias. In lib/response.js, res.contentType is defined as an alias for res.type(str), but it had no unit tests in test/res.type.js to ensure it works correctly and behaves identically.
  2. Preserving media type parameters (like charsets or custom parameters) when passing type/subtype strings directly to res.type(str) (e.g. res.type('text/html; charset=utf-8')).

Changes

  • test/res.type.js:
    • Added test case for parameter preservation when calling res.type().
    • Added a .contentType(str) test block to verify that the alias behaves identically to res.type() for file lookups, literal types, and literal types with parameters.

Checklist

  • All tests pass locally (npx mocha test/res.type.js passed)
  • Code conforms to ESLint formatting standards (npm run lint passed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant