* Implement support for variadic arguments to `m.fragment` While I was at it, I refactored the common logic out of `hyperscript`. * Add a missed change from #2326 * Update docs + changelog [skip ci] * Explain rationale for `hyperscriptVnode`'s calling convention This way, it doesn't get erroneously "cleaned up" into something worse, and so it's clearer how it'd be potentially optimized once ES5 support is dropped.
197 lines
5.5 KiB
JavaScript
197 lines
5.5 KiB
JavaScript
"use strict"
|
|
|
|
var o = require("../../ospec/ospec")
|
|
var fragment = require("../../render/fragment")
|
|
|
|
o.spec("fragment", function() {
|
|
o("works", function() {
|
|
var attrs = {foo: 5}
|
|
var child = {tag: "p"}
|
|
var frag = fragment(attrs, [child])
|
|
|
|
o(frag.tag).equals("[")
|
|
|
|
o(Array.isArray(frag.children)).equals(true)
|
|
o(frag.children.length).equals(1)
|
|
o(frag.children[0]).equals(child)
|
|
|
|
o(frag.attrs).equals(attrs)
|
|
|
|
o(frag.key).equals(undefined)
|
|
})
|
|
o("supports keys", function() {
|
|
var attrs = {key: 7}
|
|
var frag = fragment(attrs, [])
|
|
o(frag.tag).equals("[")
|
|
|
|
o(Array.isArray(frag.children)).equals(true)
|
|
o(frag.children.length).equals(0)
|
|
|
|
o(frag.attrs).equals(attrs)
|
|
o(frag.attrs.key).equals(7)
|
|
|
|
o(frag.key).equals(7)
|
|
})
|
|
o.spec("children with no attrs", function() {
|
|
o("handles string single child", function() {
|
|
var vnode = fragment(["a"])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("a")
|
|
})
|
|
o("handles falsy string single child", function() {
|
|
var vnode = fragment([""])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
})
|
|
o("handles number single child", function() {
|
|
var vnode = fragment([1])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(1)
|
|
})
|
|
o("handles falsy number single child", function() {
|
|
var vnode = fragment([0])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(0)
|
|
})
|
|
o("handles boolean single child", function() {
|
|
var vnode = fragment([true])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(true)
|
|
})
|
|
o("handles falsy boolean single child", function() {
|
|
var vnode = fragment([false])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
})
|
|
o("handles null single child", function() {
|
|
var vnode = fragment([null])
|
|
|
|
o(vnode.children[0]).equals(null)
|
|
})
|
|
o("handles undefined single child", function() {
|
|
var vnode = fragment([undefined])
|
|
|
|
o(vnode.children[0]).equals(undefined)
|
|
})
|
|
o("handles multiple string children", function() {
|
|
var vnode = fragment(["", "a"])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals("a")
|
|
})
|
|
o("handles multiple number children", function() {
|
|
var vnode = fragment([0, 1])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(0)
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals(1)
|
|
})
|
|
o("handles multiple boolean children", function() {
|
|
var vnode = fragment([false, true])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals(true)
|
|
})
|
|
o("handles multiple null/undefined child", function() {
|
|
var vnode = fragment([null, undefined])
|
|
|
|
o(vnode.children[0]).equals(null)
|
|
o(vnode.children[1]).equals(undefined)
|
|
})
|
|
o("handles falsy number single child without attrs", function() {
|
|
var vnode = fragment(0)
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(0)
|
|
})
|
|
})
|
|
o.spec("children with attrs", function() {
|
|
o("handles string single child", function() {
|
|
var vnode = fragment({}, ["a"])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("a")
|
|
})
|
|
o("handles falsy string single child", function() {
|
|
var vnode = fragment({}, [""])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
})
|
|
o("handles number single child", function() {
|
|
var vnode = fragment({}, [1])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(1)
|
|
})
|
|
o("handles falsy number single child", function() {
|
|
var vnode = fragment({}, [0])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(0)
|
|
})
|
|
o("handles boolean single child", function() {
|
|
var vnode = fragment({}, [true])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(true)
|
|
})
|
|
o("handles falsy boolean single child", function() {
|
|
var vnode = fragment({}, [false])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
})
|
|
o("handles null single child", function() {
|
|
var vnode = fragment({}, [null])
|
|
|
|
o(vnode.children[0]).equals(null)
|
|
})
|
|
o("handles undefined single child", function() {
|
|
var vnode = fragment({}, [undefined])
|
|
|
|
o(vnode.children[0]).equals(undefined)
|
|
})
|
|
o("handles multiple string children", function() {
|
|
var vnode = fragment({}, ["", "a"])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals("a")
|
|
})
|
|
o("handles multiple number children", function() {
|
|
var vnode = fragment({}, [0, 1])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals(0)
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals(1)
|
|
})
|
|
o("handles multiple boolean children", function() {
|
|
var vnode = fragment({}, [false, true])
|
|
|
|
o(vnode.children[0].tag).equals("#")
|
|
o(vnode.children[0].children).equals("")
|
|
o(vnode.children[1].tag).equals("#")
|
|
o(vnode.children[1].children).equals(true)
|
|
})
|
|
o("handles multiple null/undefined child", function() {
|
|
var vnode = fragment({}, [null, undefined])
|
|
|
|
o(vnode.children[0]).equals(null)
|
|
o(vnode.children[1]).equals(undefined)
|
|
})
|
|
})
|
|
})
|