axios-mock-adapter
axios-mock-adapter copied to clipboard
Disallow upper-case characters in mocked headers
The Response section of the Axios README contains a subtle detail:
//
headersthe headers that the server responded with // All header names are lower cased
This behavior recently bit me after migrating from another HTTP lib – the property used to be accessible as headers.Date, but after migrating to Axios the property was instead accessible as headers.date. Our tests didn't discover it since they looked something like this:
mockedAxios.onGet("/some-url/").reply(200, "", { Date: "2019-01-01" })
Since headers are always lowercase when accessing them with Axios, it should be an error to create a mock response with non-lowercase header names. Alternatively, mock adapter should lower-case them automatically, but I feel that might be harder to debug.
I'm happy to contribute with a PR, just want a second opinion first.