toolkit/javascript/d3/test/core/html-test.js
author Nicolas Sauret <nicolas.sauret@iri.centrepompidou.fr>
Thu, 10 Apr 2014 14:20:23 +0200
changeset 47 c0b4a8b5a012
permissions -rw-r--r--
add toolkit.html + démonstrateurs

require("../env");
require("../../d3");

var vows = require("vows"),
    assert = require("assert");

var suite = vows.describe("d3.html");

suite.addBatch({
  "html": {
    topic: function() {
      var cb = this.callback;
      return d3.html("examples/data/sample.html", function(document) {
        cb(null, document);
      });
    },
    "invokes the callback with the loaded html": function(document) {
      assert.equal(document.getElementsByTagName("H1")[0].textContent, "Hello & world!");
    },
    "override the mime type to text/html": function(xml) {
      assert.equal(XMLHttpRequest._last._info.mimeType, "text/html");
    },
    "": {
      topic: function() {
        var cb = this.callback;
        return d3.html("//does/not/exist.html", function(document) {
          cb(null, document);
        });
      },
      "invokes the callback with null when an error occurs": function(document) {
        assert.isNull(document);
      }
    }
  }
});

suite.export(module);