Skip to content

Commit

Permalink
Allow extra qualifications when matching json content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
slackersoft committed Jun 12, 2014
1 parent d893394 commit 54864a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mock-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions spec/javascripts/fake-xml-http-request-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 54864a4

Please sign in to comment.