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/package.json b/package.json index 7813820..1c9eed0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coreapi", - "version": "0.1.0", + "version": "0.1.1", "description": "Javascript client library for Core API", "main": "lib/index.js", "scripts": { 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)