
Summary: Move dom creation into katex.js so our tests can test non-dom things, and add some buildTree tests. Add some checks make utils.js work in node. Add support for jasmine-node, to allow for command line unit testing. Test Plan: - Make sure tests work, in both the browser and with `make test` - Make sure huxley screenshots didn't change Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D13125
47 lines
1007 B
JavaScript
47 lines
1007 B
JavaScript
var nativeIndexOf = Array.prototype.indexOf;
|
|
var indexOf = function(list, elem) {
|
|
if (list == null) {
|
|
return -1;
|
|
}
|
|
if (nativeIndexOf && list.indexOf === nativeIndexOf) {
|
|
return list.indexOf(elem);
|
|
}
|
|
var i = 0, l = list.length;
|
|
for (; i < l; i++) {
|
|
if (list[i] === elem) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
};
|
|
|
|
var contains = function(list, elem) {
|
|
return indexOf(list, elem) !== -1;
|
|
};
|
|
|
|
var setTextContent;
|
|
|
|
if (typeof document !== "undefined") {
|
|
var testNode = document.createElement("span");
|
|
if ("textContent" in testNode) {
|
|
setTextContent = function(node, text) {
|
|
node.textContent = text;
|
|
};
|
|
} else {
|
|
setTextContent = function(node, text) {
|
|
node.innerText = text;
|
|
};
|
|
}
|
|
}
|
|
|
|
function clearNode(node) {
|
|
setTextContent(node, "");
|
|
}
|
|
|
|
module.exports = {
|
|
contains: contains,
|
|
indexOf: indexOf,
|
|
setTextContent: setTextContent,
|
|
clearNode: clearNode
|
|
};
|