diff --git a/lib/mock-ajax.js b/lib/mock-ajax.js index 262a2ac..aac8c98 100644 --- a/lib/mock-ajax.js +++ b/lib/mock-ajax.js @@ -117,7 +117,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. var defaults = [ { test: function(xhr) { - return xhr.contentType() === 'application/json'; + return /^application\/json/.test(xhr.contentType()); }, parse: function jsonParser(paramString) { return JSON.parse(paramString); diff --git a/spec/javascripts/fake-xml-http-request-spec.js b/spec/javascripts/fake-xml-http-request-spec.js index 8e7eac9..197414f 100644 --- a/spec/javascripts/fake-xml-http-request-spec.js +++ b/spec/javascripts/fake-xml-http-request-spec.js @@ -145,6 +145,23 @@ describe("FakeXMLHttpRequest", function() { expect(xhr.data()).toEqual(data); }); + it("should parse json even if there are further qualifiers", function() { + var data = { + foo: 'bar', + baz: ['q', 'u', 'u', 'x'], + nested: { + object: { + with: 'stuff' + } + } + }; + + xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); + xhr.send(JSON.stringify(data)); + + expect(xhr.data()).toEqual(data); + }); + it("should be able to use a custom parser", function() { xhr.send('custom_format'); var custom = {