Merge remote-tracking branch 'upstream/next' into merge
This commit is contained in:
commit
544bb503b9
162 changed files with 25832 additions and 623 deletions
|
|
@ -293,12 +293,13 @@ describe("m.deferred()", function () {
|
|||
prmA.resolve("A")
|
||||
prmB.resolve("B")
|
||||
|
||||
prmA.promise.then(function (A) {
|
||||
prmA.promise.then(function () {
|
||||
return prmB.promise
|
||||
}).then(function (B) {
|
||||
expect(B).to.equal("B")
|
||||
})
|
||||
})
|
||||
|
||||
it("yields immutable promises", function () {
|
||||
var d = m.deferred()
|
||||
d.resolve(5)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ describe("m()", function () {
|
|||
expect(m("[title=bar]")).to.have.deep.property("attrs.title", "bar")
|
||||
})
|
||||
|
||||
it("sets attr without a value as an empty string", function () {
|
||||
expect(m("[empty]")).to.have.deep.property("attrs.empty", true)
|
||||
})
|
||||
|
||||
it("sets correct single quoted attr", function () {
|
||||
expect(m("[title=\'bar\']")).to.have.deep.property("attrs.title", "bar")
|
||||
})
|
||||
|
|
@ -213,4 +217,12 @@ describe("m()", function () {
|
|||
m.component(component, args).controller()
|
||||
expect(spy.secondCall).to.have.been.calledWith(args)
|
||||
})
|
||||
|
||||
it("does not proxy to m.component() if the object does not have .view() method", function () {
|
||||
var component = {}
|
||||
|
||||
var args = {age: 12}
|
||||
|
||||
expect(m.bind(m, component, args)).to.throw()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -42,6 +42,22 @@ describe("m.prop()", function () {
|
|||
expect(JSON.stringify(obj)).to.equal('{"prop":"test"}')
|
||||
})
|
||||
|
||||
it("correctly stringifies Date", function () {
|
||||
var prop = m.prop(new Date(999))
|
||||
expect(JSON.stringify(prop)).to.equal('"1970-01-01T00:00:00.999Z"')
|
||||
})
|
||||
|
||||
it("correctly stringifies object with toJSON method", function () {
|
||||
function Thing(name) {
|
||||
this.name = name
|
||||
}
|
||||
Thing.prototype.toJSON = function() {
|
||||
return {kind: 'Thing', name: this.name}
|
||||
}
|
||||
var banana = m.prop(new Thing("bannana"))
|
||||
expect(JSON.stringify(banana)).to.equal('{"kind":"Thing","name":"bannana"}')
|
||||
})
|
||||
|
||||
it("correctly wraps Mithril promises", function () {
|
||||
var defer = m.deferred()
|
||||
var prop = m.prop(defer.promise)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,24 @@ describe("m.render()", function () {
|
|||
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
|
||||
})
|
||||
|
||||
it("renders `null` body to empty string", function () {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [null]))
|
||||
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
|
||||
})
|
||||
|
||||
it("renders `true` body to empty string", function () {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [true]))
|
||||
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
|
||||
})
|
||||
|
||||
it("renders `false` body to empty string", function () {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("div", [false]))
|
||||
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
|
||||
})
|
||||
|
||||
it("uses the W3C URI as default namespace for SVG children", function () {
|
||||
var root = mock.document.createElement("div")
|
||||
m.render(root, m("svg", [m("g")]))
|
||||
|
|
@ -1550,6 +1568,16 @@ describe("m.render()", function () {
|
|||
.to.equal('<option value="">aaa</option>')
|
||||
})
|
||||
|
||||
it("sets correct <select> value", function () {
|
||||
var root = document.createElement("div")
|
||||
m.render(root, m("select", {value: "b"}, [
|
||||
m("option", {value: "a"}, "aaa"),
|
||||
m("option", {value: "b"}, "bbb")
|
||||
]))
|
||||
// This works only if select value is set after its options exist.
|
||||
expect(root.childNodes[0].value).to.equal("b")
|
||||
})
|
||||
|
||||
it("caches children of editable on update", function () {
|
||||
var root = document.createElement("span")
|
||||
var t1 = m.trust("<h1>fo</h1>o")
|
||||
|
|
|
|||
|
|
@ -195,6 +195,12 @@ describe("m.request()", function () {
|
|||
expect(prop().url).to.equal("/test")
|
||||
})
|
||||
|
||||
it("ignores interpolations without data", function () { // eslint-disable-line
|
||||
var prop = m.request({method: "GET", url: "/test:notfound", data: {foo: 1}})
|
||||
resolve()
|
||||
expect(prop().url).to.equal("/test:notfound?foo=1")
|
||||
})
|
||||
|
||||
it("appends children in query strings to `url` from `data` for `GET`", function () { // eslint-disable-line
|
||||
var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}})
|
||||
resolve()
|
||||
|
|
|
|||
|
|
@ -102,8 +102,7 @@ describe("m.route()", function () {
|
|||
expect(route2).to.equal("/test13")
|
||||
})
|
||||
|
||||
// FIXME: this causes others to fail
|
||||
xdit("skips route change if component ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
dit("skips route change if component ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
mode("search")
|
||||
var spy = sinon.spy()
|
||||
|
||||
|
|
@ -128,70 +127,10 @@ describe("m.route()", function () {
|
|||
route("/b")
|
||||
|
||||
expect(spy).to.not.have.been.called
|
||||
expect(m.route()).to.equal("/a")
|
||||
})
|
||||
|
||||
// FIXME: this causes others to fail
|
||||
xdit("skips route change if subcomponent ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
mode("search")
|
||||
|
||||
var spy = sinon.spy()
|
||||
|
||||
var subsub = {
|
||||
controller: function () {
|
||||
this.onunload = function (e) { e.preventDefault() }
|
||||
},
|
||||
view: function () {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
|
||||
var sub = pure(function () { return subsub })
|
||||
|
||||
route(root, "/a", {
|
||||
"/a": pure(function () { return sub }),
|
||||
|
||||
"/b": {
|
||||
controller: spy,
|
||||
view: noop
|
||||
}
|
||||
})
|
||||
|
||||
route("/b")
|
||||
|
||||
expect(spy).to.not.have.been.called
|
||||
})
|
||||
|
||||
// FIXME: this causes others to fail
|
||||
xdit("skips route change if non-curried component ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
mode("search")
|
||||
|
||||
var spy = sinon.spy()
|
||||
|
||||
var sub = {
|
||||
controller: function () {
|
||||
this.onunload = function (e) { e.preventDefault() }
|
||||
},
|
||||
view: function () {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
|
||||
route(root, "/a", {
|
||||
"/a": pure(function () { return sub }),
|
||||
|
||||
"/b": {
|
||||
controller: spy,
|
||||
view: noop
|
||||
}
|
||||
})
|
||||
|
||||
route("/b")
|
||||
|
||||
expect(spy).to.not.have.been.called
|
||||
})
|
||||
|
||||
// FIXME: this causes others to fail
|
||||
xdit("skips route change if non-curried subcomponent ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
dit("skips route change if subcomponent ctrl.onunload calls preventDefault", function (root) { // eslint-disable-line
|
||||
mode("search")
|
||||
|
||||
var spy = sinon.spy()
|
||||
|
|
@ -219,6 +158,7 @@ describe("m.route()", function () {
|
|||
route("/b")
|
||||
|
||||
expect(spy).to.not.have.been.called
|
||||
expect(m.route()).to.equal("/a")
|
||||
})
|
||||
|
||||
dit("initializes a component's constructor on route change", function (root) { // eslint-disable-line
|
||||
|
|
@ -898,6 +838,36 @@ describe("m.route()", function () {
|
|||
expect(mock.history.$$length).to.equal(0)
|
||||
})
|
||||
|
||||
dit("modify history when redirecting to same route with different parameters", function(root) {
|
||||
mode("search")
|
||||
mock.history.$$length = 0
|
||||
|
||||
route(root, "/a", {
|
||||
"/a": pure(function () { return "a" }),
|
||||
"/b": pure(function () { return "b" })
|
||||
})
|
||||
|
||||
route("/b")
|
||||
route("/b", { foo: "bar" })
|
||||
|
||||
expect(mock.history.$$length).to.equal(2)
|
||||
})
|
||||
|
||||
dit("doesn't modify history when redirecting to same route with same parameters", function(root) {
|
||||
mode("search")
|
||||
mock.history.$$length = 0
|
||||
|
||||
route(root, "/a", {
|
||||
"/a": pure(function () { return "a" }),
|
||||
"/b": pure(function () { return "b" })
|
||||
})
|
||||
|
||||
route("/b", { foo: "bar" })
|
||||
route("/b", { foo: "bar" })
|
||||
|
||||
expect(mock.history.$$length).to.equal(1)
|
||||
})
|
||||
|
||||
context("m.route.strategy() === \"all\", identical views", function () {
|
||||
context("parent nodes", function () {
|
||||
dit("renders routes independently", function (root) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ describe("m.trust()", function () {
|
|||
// FIXME: implement document.createRange().createContextualFragment() in the
|
||||
// mock window for these tests
|
||||
dom(function () {
|
||||
|
||||
it("isn't escaped in m.render()", function () {
|
||||
var root = document.createElement("div")
|
||||
m.render(root, m("div", "a", m.trust("&"), "b"))
|
||||
|
|
@ -57,12 +56,61 @@ describe("m.trust()", function () {
|
|||
it("works with trusted content in div", function () {
|
||||
var root = document.createElement("div")
|
||||
m.render(root, m("div", [
|
||||
m("p", "©"),
|
||||
m("p", m.trust("©")),
|
||||
m.trust("©"),
|
||||
m("p", "©"),
|
||||
m("p", m.trust("©")),
|
||||
m.trust("©")
|
||||
]))
|
||||
expect(root.innerHTML).to.equal("<div><p>&copy;</p><p>©</p>©</div>")
|
||||
|
||||
expect(root.innerHTML)
|
||||
.to.equal("<div><p>&copy;</p><p>©</p>©</div>")
|
||||
})
|
||||
|
||||
// https://github.com/lhorie/mithril.js/issues/1045
|
||||
it("correctly injects script tags and executes them", function () {
|
||||
var HTMLString =
|
||||
"<script>document.getElementById('root').innerText='After'</script>"
|
||||
var root = document.createElement("div")
|
||||
var child = document.createElement("div")
|
||||
root.id = "root"
|
||||
root.innerText = "Before"
|
||||
root.appendChild(child)
|
||||
document.body.appendChild(root)
|
||||
|
||||
m.render(child, m.trust(HTMLString))
|
||||
|
||||
expect(root.innerText).to.equal("After")
|
||||
})
|
||||
|
||||
// https://github.com/lhorie/mithril.js/issues/956
|
||||
it("works with many and nested tags in trusted content", function () {
|
||||
var page = {
|
||||
names: m.prop(["John", "Paul", "George", "Ringo"]),
|
||||
nodeString: function (name) {
|
||||
return "<div><p>Hi </p></div><div><p>" + name + "</p></div>"
|
||||
},
|
||||
view: function () {
|
||||
return m("div",
|
||||
this.names().map(function (name) {
|
||||
return m.trust(this.nodeString(name))
|
||||
}, this)
|
||||
)
|
||||
}
|
||||
}
|
||||
m.render(document.body, page)
|
||||
var root = document.body.children[0]
|
||||
expect(root.children.length).to.equal(2 * page.names().length)
|
||||
for (var i = 0; i < page.names().length; i++) {
|
||||
var section = root.children[2 * i + 1]
|
||||
expect(section.children[0].innerText).to.equal(page.names()[i])
|
||||
}
|
||||
|
||||
page.names(["Jack", "Jill"])
|
||||
m.render(document.body, page)
|
||||
expect(root.children.length).to.equal(2 * page.names().length)
|
||||
for (i = 0; i < page.names().length; i++) {
|
||||
section = root.children[2 * i + 1]
|
||||
expect(section.children[0].innerText).to.equal(page.names()[i])
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue