toolkit/javascript/d3/test/core/xml-test.js
changeset 47 c0b4a8b5a012
equal deleted inserted replaced
46:efd9c589177a 47:c0b4a8b5a012
       
     1 require("../env");
       
     2 require("../../d3");
       
     3 
       
     4 var vows = require("vows"),
       
     5     assert = require("assert");
       
     6 
       
     7 var suite = vows.describe("d3.xml");
       
     8 
       
     9 suite.addBatch({
       
    10   "xml": {
       
    11     topic: function() {
       
    12       var cb = this.callback;
       
    13       return d3.xml("examples/data/sample.xml", function(xml) {
       
    14         cb(null, xml);
       
    15       });
       
    16     },
       
    17     "invokes the callback with the loaded xml": function(xml) {
       
    18       assert.deepEqual(xml, {_xml: "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<hello>\n  <world name=\"Earth\"/>\n</hello>\n"});
       
    19     },
       
    20     "does not override the mime type by default": function(xml) {
       
    21       assert.isUndefined(XMLHttpRequest._last._info.mimeType);
       
    22     },
       
    23     "": {
       
    24       topic: function() {
       
    25         var cb = this.callback;
       
    26         return d3.xml("examples/data/sample.txt", "application/xml+sample", function(xml) {
       
    27           cb(null, xml);
       
    28         });
       
    29       },
       
    30       "observes the optional mime type": function(xml) {
       
    31         assert.equal(XMLHttpRequest._last._info.mimeType, "application/xml+sample");
       
    32       }
       
    33     },
       
    34     " ": {
       
    35       topic: function() {
       
    36         var cb = this.callback;
       
    37         return d3.xml("//does/not/exist.xml", function(xml) {
       
    38           cb(null, xml);
       
    39         });
       
    40       },
       
    41       "invokes the callback with null when an error occurs": function(xml) {
       
    42         assert.isNull(xml);
       
    43       }
       
    44     }
       
    45   }
       
    46 });
       
    47 
       
    48 suite.export(module);