Merge pull request #1305 from pygy/validate-root-node
Validate the DOM node passed to `render`
This commit is contained in:
commit
6fdfcbb852
4 changed files with 30 additions and 0 deletions
|
|
@ -22,6 +22,16 @@ o.spec("mount", function() {
|
|||
render = coreRenderer($window).render
|
||||
})
|
||||
|
||||
o("throws on invalid `root` DOM node", function() {
|
||||
var threw = false
|
||||
try {
|
||||
mount(null, {view: function() {}})
|
||||
} catch (e) {
|
||||
threw = true
|
||||
}
|
||||
o(threw).equals(true)
|
||||
})
|
||||
|
||||
o("renders into `root`", function() {
|
||||
mount(root, {
|
||||
view : function() {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,16 @@ o.spec("route", function() {
|
|||
route.prefix(prefix)
|
||||
})
|
||||
|
||||
o("throws on invalid `root` DOM node", function() {
|
||||
var threw = false
|
||||
try {
|
||||
route(null, '/', {'/':{view: function() {}}})
|
||||
} catch (e) {
|
||||
threw = true
|
||||
}
|
||||
o(threw).equals(true)
|
||||
})
|
||||
|
||||
o("renders into `root`", function() {
|
||||
$window.location.href = prefix + "/"
|
||||
route(root, "/", {
|
||||
|
|
|
|||
|
|
@ -515,6 +515,7 @@ module.exports = function($window) {
|
|||
}
|
||||
|
||||
function render(dom, vnodes) {
|
||||
if (!dom) throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.")
|
||||
var hooks = []
|
||||
var active = $doc.activeElement
|
||||
|
||||
|
|
|
|||
|
|
@ -21,4 +21,13 @@ o.spec("render", function() {
|
|||
|
||||
o(root.childNodes.length).equals(0)
|
||||
})
|
||||
o("throws on invalid root node", function(){
|
||||
var threw = false
|
||||
try {
|
||||
render(null, [])
|
||||
} catch (e) {
|
||||
threw = true
|
||||
}
|
||||
o(threw).equals(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue