superagent-mocker icon indicating copy to clipboard operation
superagent-mocker copied to clipboard

Request Headers are lowercased

Open LeopoldoFu opened this issue 9 years ago • 0 comments

The headers in the request object passed into the callback for get or post mocks are getting lower-cased. While generally speaking, http headers are case-insensitive, it may actually matter for some http handling implementations.

import {default as request} from 'superagent';
import superagentMocker from 'superagent-mocker';

describe('making an api call', function() {

        beforeEach(function(done) {
            const mock = this.mock = superagentMocker(request);
            const data = this.data = {
                someDataProp: 'data!'
            };
            mock.get('/api/some-url', (req) => {
            // req.headers keys are all lowercased. They should not be
            this.request = req;
            return {body: data};
        });

        const promise = getData();
        promise.then(() => done()).catch(done);
    });

    it('should have correct headers', function() {
        expect(this.request).to.have.deep.property('headers.Authorization', 'Bearer some token');
    });

});

LeopoldoFu avatar Feb 03 '16 19:02 LeopoldoFu