jest-express / jest-express

Mock Express for testing with Jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Headers key should be in lowercase

dels07 opened this issue · comments

Describe the bug
I tried test with code that read custom headers and use lowercase version of header key.

To Reproduce
Steps to reproduce the behavior:

// in test file
request.setHeader({ 'FOO-HEADER': 'foo', 'BAR-HEADER': 'bar'})

// in actual code
const fooHeader = request.headers['foo-header'] // return null
const barHeader = request.headers['BAR-HEADER'] // return 'bar'

Expected behavior
Headers should be in lowercase, according to node specification

node-mocks-http already support this

Environment (please complete the following information):

  • Node: 10.16.x
  • Express: ^4.17
  • Jest: ^24.9
  • Jest-Express: 1.10.1

request.ts:108

if (options.headers) {
   const o = options.headers;
   const headers = Object.keys(o).reduce((c, k) => (c[k.toLowerCase()] = o[k], c), {});
   this.headers = Object.assign({}, headers);
}

I'm new to typescript, when I tried to modify this line, I got message

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)

Edit: nvm I use for of loop as another example in request.ts, making a pull-request

Awesome @dels07 thank you for the work you put in on fixing this. 👍