Comparing version 0.1.1 to 0.1.2
# Pact History | ||
## Version 0.1.2 (2011-03-29) | ||
* Parse JSON responses even when the content-type includes a charset. (Ryan Grove) | ||
## Version 0.1.1 (2011-03-29) | ||
@@ -4,0 +8,0 @@ |
@@ -21,3 +21,3 @@ /*! | ||
response.on("end", function () { | ||
if (response.headers["content-type"] === "application/json") { | ||
if (/^application\/json\s*(?:;|$)/.test(response.headers["content-type"])) { | ||
data = JSON.parse(data); | ||
@@ -24,0 +24,0 @@ } |
@@ -9,4 +9,7 @@ { | ||
], | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Reid Burke <me@reidburke.com> (http://reidburke.com/)", | ||
"contributors" : [ | ||
"Ryan Grove <ryan@wonko.com>" | ||
], | ||
"main": "index", | ||
@@ -13,0 +16,0 @@ "directories": { |
26
test.js
@@ -19,3 +19,3 @@ /*! | ||
}), port).apply(this); | ||
} | ||
}; | ||
} | ||
@@ -44,2 +44,26 @@ | ||
} | ||
}, | ||
}, | ||
'A JSON API' : { | ||
topic: mockServer(function(req, res) { | ||
if (req.url === '/') { | ||
res.writeHead(200, {'Content-Type': 'application/json'}); | ||
} else if (req.url == '/with-charset') { | ||
res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8'}); | ||
} | ||
res.end('{"foo": "bar"}'); | ||
}), | ||
'when / is requested' : { | ||
topic: pact.request(), | ||
'contains a parsed JSON response object' : function(topic) { | ||
assert.isObject(topic.body); | ||
assert.strictEqual(topic.body.foo, 'bar'); | ||
} | ||
}, | ||
'when /with-charset is requested' : { | ||
topic: pact.request(), | ||
'contains a parsed JSON response object' : function(topic) { | ||
assert.isObject(topic.body); | ||
assert.strictEqual(topic.body.foo, 'bar'); | ||
} | ||
} | ||
@@ -46,0 +70,0 @@ }, |
65345
324