Skip to content

Commit 54864a4

Browse files
author
slackersoft
committed
Allow extra qualifications when matching json content-type
1 parent d893394 commit 54864a4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/mock-ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
117117
var defaults = [
118118
{
119119
test: function(xhr) {
120-
return xhr.contentType() === 'application/json';
120+
return /^application\/json/.test(xhr.contentType());
121121
},
122122
parse: function jsonParser(paramString) {
123123
return JSON.parse(paramString);

spec/javascripts/fake-xml-http-request-spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ describe("FakeXMLHttpRequest", function() {
145145
expect(xhr.data()).toEqual(data);
146146
});
147147

148+
it("should parse json even if there are further qualifiers", function() {
149+
var data = {
150+
foo: 'bar',
151+
baz: ['q', 'u', 'u', 'x'],
152+
nested: {
153+
object: {
154+
with: 'stuff'
155+
}
156+
}
157+
};
158+
159+
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
160+
xhr.send(JSON.stringify(data));
161+
162+
expect(xhr.data()).toEqual(data);
163+
});
164+
148165
it("should be able to use a custom parser", function() {
149166
xhr.send('custom_format');
150167
var custom = {

0 commit comments

Comments
 (0)