Skip to content

Instantly share code, notes, and snippets.

@PatrickKing
Last active October 13, 2016 00:00
Show Gist options
  • Save PatrickKing/36983f91937ead08dd19a2455a11458c to your computer and use it in GitHub Desktop.
Save PatrickKing/36983f91937ead08dd19a2455a11458c to your computer and use it in GitHub Desktop.
Behaviour of setAttributeNS in jsdom
var jsdom = require("jsdom");
var html = '<html><svg "xmlns=http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100"></svg></html>';
jsdom.env({
features: {
QuerySelector: true
},
html: html,
done: function(errors, window) {
var image = window.document.createElement("IMAGE");
window.document.querySelector('svg').appendChild(image);
// image.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', 'my_image.svg');
// Produces: <image xlink:href="my_image.svg"></image>
image.setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'my_image.svg');
// Produces: <image href="my_image.svg"></image>
// D3 makes calls like this.
console.log(window.document.querySelector('image').outerHTML)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment