diff --git a/lib/utils.js b/lib/utils.js index a969bb6..60b127f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -14,7 +14,7 @@ const determineTransport = function (transports, url) { } const negotiateDecoder = function (decoders, contentType) { - if (contentType === undefined) { + if (contentType === undefined || contentType === null) { return decoders[0] } diff --git a/tests/utils.js b/tests/utils.js index eb88558..fe31ec3 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -29,6 +29,12 @@ describe('Test the Utils/negotiateDecoder function', function () { expect(result instanceof coreapi.codecs.CoreJSONCodec).toBeTruthy() }) + it('should return the default decoder if content type is null', function () { + const contentType = null + const result = utils.negotiateDecoder(decoders, contentType) + expect(result instanceof coreapi.codecs.CoreJSONCodec).toBeTruthy() + }) + it('should return the decoder for a content type (application/json)', function () { const contentType = 'application/json' const result = utils.negotiateDecoder(decoders, contentType)