add tests

This commit is contained in:
Leo Horie 2015-02-06 22:08:08 -05:00
parent 4259c06a0a
commit 57021b6b5e
2 changed files with 64 additions and 0 deletions

View file

@ -33,6 +33,14 @@ function testMithril(mock) {
test(function() {return m("div", {class: ""}).attrs.className === undefined})
test(function() {return m("div", {className: ""}).attrs.class === undefined})
test(function() {return m("div", {class: ""}).attrs.class === undefined})
test(function() {return m("div", [1, 2, 3], 4).children.length === 2})
test(function() {return m("div", [1, 2, 3], 4).children[0].length === 3})
test(function() {return m("div", [1, 2, 3], 4).children[1] === 4})
test(function() {return m("div", [1, 2, 3]).children.length === 3})
test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children.length === 2})
test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[0].length === 3})
test(function() {return m("div", [1, 2, 3], [4, 5, 6, 7]).children[1].length === 4})
test(function() {return m("div", [1], [2], [3]).children.length === 3})
//m.module
test(function() {
@ -1684,6 +1692,60 @@ function testMithril(mock) {
return mock.location.search == "?/b?foo=2"
})
test(function() {
mock.requestAnimationFrame.$resolve()
mock.location.search = "?"
mock.history.$$length = 0
var root = mock.document.createElement("div")
var a = {}
a.controller = function() {}
a.view = function() {return "a"}
var b = {}
b.controller = function() {}
b.view = function() {return "b"}
m.route(root, "/a", {
"/a": a,
"/b": b,
})
mock.requestAnimationFrame.$resolve()
m.route("/b")
mock.requestAnimationFrame.$resolve()
return mock.history.$$length == 1
})
test(function() {
mock.requestAnimationFrame.$resolve()
mock.location.search = "?"
mock.history.$$length = 0
var root = mock.document.createElement("div")
var a = {}
a.controller = function() {}
a.view = function() {return "a"}
var b = {}
b.controller = function() {}
b.view = function() {return "b"}
m.route(root, "/a", {
"/a": a,
"/b": b,
})
mock.requestAnimationFrame.$resolve()
m.route("/a")
mock.requestAnimationFrame.$resolve()
return mock.history.$$length == 0
})
//end m.route
//m.prop

View file

@ -158,7 +158,9 @@ mock.window = (function() {
}())
window.location = {search: "", pathname: "", hash: ""},
window.history = {}
window.history.$$length = 0
window.history.pushState = function(data, title, url) {
window.history.$$length++
window.location.pathname = window.location.search = window.location.hash = url
},
window.history.replaceState = function(data, title, url) {