Permalink
Browse files

Making content-type checks more robust.

Newer versions of express seems to add charset to end.
  • Loading branch information...
1 parent c87069b commit 46dfdfaacc787dabeba26b0ec748949534e67161 @bbyars committed Jun 12, 2011
Showing with 10 additions and 3 deletions.
  1. +1 −1 server/test/functional/controlServer.test.js
  2. +9 −2 server/test/testExtensions.js
@@ -12,7 +12,7 @@ var testCase = require('nodeunit').testCase,
exports['GET /'] = testCase({
'returns base hypermedia': function (test) {
http.get(controlServerURL + '/', function (response) {
- test.strictEqual(response.headers['content-type'], 'application/vnd.httpmock+json; charset=utf-8');
+ test.strictEqual(response.headers['content-type'].indexOf('application/vnd.httpmock+json'), 0);
test.jsonEquals(response.body, {
links: [{
href: controlServerURL + '/servers',
@@ -38,7 +38,8 @@ var web = {
urlParts = url.parse(spec.url),
path = urlParts.pathname + (urlParts.search || ''),
client = http.createClient(urlParts.port, urlParts.hostname),
- request = client.request(spec.method, path, spec.headers);
+ request = client.request(spec.method, path, spec.headers),
+ contentType;
request.write(JSON.stringify(spec.body));
request.end();
@@ -52,7 +53,8 @@ var web = {
});
response.on('end', function () {
- if (response.headers['content-type'] === 'application/vnd.httpmock+json; charset=utf-8') {
+ contentType = response.headers['content-type'];
+ if (contentType && contentType.indexOf('application/vnd.httpmock+json') === 0) {
response.parsedBody = JSON.parse(response.body);
}
spec.callback(response);
@@ -166,6 +168,11 @@ var addCustomAsserts = function (test) {
arguments[1](test, mock);
}
};
+
+ test.matches = function (actual, expectedRegex, message) {
+ message = message || 'Expected {0} to match {1}.'.format(actual, expectedRegex);
+ test.ok(expectedRegex.test(actual), message);
+ };
};
nodeunitTypes.test = function () {

0 comments on commit 46dfdfa

Please sign in to comment.