Even better checks for the arguments to UI.insert

This commit is contained in:
Avital Oliver
2014-06-20 12:17:58 -07:00
parent 35f1dc45dd
commit 2ea77a9409
2 changed files with 7 additions and 2 deletions

View File

@@ -173,8 +173,10 @@ UI.insert = function (renderedTemplate, parentElement, nextNode) {
// parentElement must be a DOM node. in particular, can't be the
// result of a call to `$`. Can't check if `parentElement instanceof
// Node` since 'Node' is undefined in IE8.
if (typeof parentElement.nodeType !== 'number')
if (! parentElement || typeof parentElement.nodeType !== 'number')
throw new Error("'parentElement' must be a DOM node");
if (nextNode && typeof nextNode.nodeType !== 'number') // 'nextNode' is optional
throw new Error("'nextNode' must be a DOM node");
if (! renderedTemplate.dom)
throw new Error("Expected template rendered with UI.render");

View File

@@ -626,7 +626,10 @@ Tinytest.add("ui - UI.insert fails on jQuery objects", function (test) {
});
test.throws(function () {
UI.insert(UI.render(tmpl), $('body'));
}, /must be a DOM node/);
}, /'parentElement' must be a DOM node/);
test.throws(function () {
UI.insert(UI.render(tmpl), document.body, $('body'));
}, /'nextNode' must be a DOM node/);
});
Tinytest.add("ui - UI.getDataContext", function (test) {