Skip to content
Browse files

Merge pull request #76 from nicolsc/master

XML data type handling
  • Loading branch information...
2 parents 5697206 + 6959fe9 commit 84a70b6b430c9b3e66a7126acdae49182809987b @ded committed May 4, 2012
Showing with 31 additions and 1 deletion.
  1. +1 −1 make/tests.js
  2. +3 −0 src/reqwest.js
  3. +1 −0 tests/fixtures/badfixtures.xml
  4. +1 −0 tests/fixtures/fixtures.xml
  5. +25 −0 tests/tests.js
View
2 make/tests.js
@@ -13,7 +13,7 @@ var routes = {
res.write(fs.readFileSync('./tests/tests.html', 'utf8'))
res.end()
},
- '(([\\w\\-\\/]+)\\.(css|js|json|jsonp|html)$)': function (req, res, next, uri, file, ext) {
+ '(([\\w\\-\\/]+)\\.(css|js|json|jsonp|html|xml)$)': function (req, res, next, uri, file, ext) {
res.writeHead(200, {
'Expires': 0
, 'Cache-Control': 'max-age=0, no-cache, no-store'
View
3 src/reqwest.js
@@ -192,6 +192,9 @@
case 'html':
resp = r
break;
+ case 'xml':
+ resp = resp.responseXML;
+ break;
}
}
View
1 tests/fixtures/badfixtures.xml
@@ -0,0 +1 @@
+Not a valid xml document
View
1 tests/fixtures/fixtures.xml
@@ -0,0 +1 @@
+<root><boosh>boosh</boosh></root>
View
25 tests/tests.js
@@ -76,6 +76,31 @@
}
})
})
+ test('XML', 4, function(){
+ ajax({
+ url:'/tests/fixtures/fixtures.xml',
+ type:'xml',
+ success:function(resp){
+ ok(resp &&resp instanceof Document, 'XML Response is a Document')
+ ok(resp && resp.documentElement && resp.documentElement.nodeName=='root', 'XML Response root is <root>')
+ ok(resp && resp.documentElement && resp.documentElement.hasChildNodes && resp.documentElement.firstChild.nodeName=='boosh' && resp.documentElement.firstChild.firstChild.nodeValue==='boosh', 'Correct XML response')
+ },
+ error:function(err){
+ ok(false, err.responseText)
+ }
+ })
+
+ ajax({
+ url:'/tests/fixtures/badfixtures.xml',
+ type:'xml',
+ success:function(resp){
+ ok(resp===null, 'No XML Response')
+ },
+ error:function(err){
+ ok(true, 'No XML Response')
+ }
+ })
+ })
})
sink('JSONP', function (test, ok) {

0 comments on commit 84a70b6

Please sign in to comment.
Something went wrong with that request. Please try again.