can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
61 lines (54 loc) • 1.88 kB
HTML
<html>
<head>
<title>testing dom-prop</title>
<script src="../dojo.js" data-dojo-config="isDebug:true"></script>
<script>
require(["dojo", "doh", "dojo/dom-prop", "dojo/dom", "dojo/domReady!"], function(dojo, doh, domProp, dom){
doh.register([
{
name: "set / get Attribute",
runTest: function(t){
var node = dom.byId("node"),
content = domProp.get(dom.byId("content1"), "textContent"),
content2 = domProp.get(dom.byId("content2"), "textContent"),
content3 = domProp.get(dom.byId("content3"), "textContent"),
content4 = domProp.get(dom.byId("content4"), "textContent");
node.innerHTML = "" //empty the node before testing
doh.is(true, content != null); //test is getter works
doh.is("Etiam", content.substr(0, 5)); //test if getters return the expected value
domProp.set(node, "textContent", content);
doh.is(content, node.innerHTML); //test is setter works (no text transformation exepcted because it's just a simple word)
domProp.set(node, "textContent", "<b>this is bold</b>");
doh.is(-1, node.innerHTML.indexOf("<")); //test if setter escape properly the content
domProp.set(node, "textContent", content2);
var test = node.innerHTML.replace(/\n/g, "");
doh.is(-1, test.indexOf("(comment)")); //test if html comments are ignored
doh.is(content4, content3);
}
}
]);
doh.run();
});
</script>
</head>
<body>
<div id="content1">Etiam</div>
<div id="content2">
<!-- <p>This should not show (comment).</p>-->
</div>
<div id="content3">
first line
second line
third line
fourth line
</div>
<div id="content4">
first line
<span>second line</span>
<span> <span>third line</span></span>
fourth line
</div>
<pre id="node"></pre>
</body>
</html>