Added tests for other kinds of string
This commit is contained in:
parent
9ae6d0ede1
commit
e94a0a7c22
2 changed files with 33 additions and 2 deletions
|
|
@ -1,9 +1,10 @@
|
|||
Mithril = m = new function app(window, undefined) {
|
||||
var sObj = "[object Object]", sArr = "[object Array]";
|
||||
var sObj = "[object Object]", sArr = "[object Array]", sStr = "[object String]"
|
||||
function type(obj) {return {}.toString.call(obj)}
|
||||
function isObj(obj) {return type(obj) == sObj}
|
||||
function isArr(obj) {return type(obj) == sArr}
|
||||
function isFn(obj) {return typeof obj == "function"}
|
||||
function isStr(obj){ return type(obj) == sStr}
|
||||
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/
|
||||
var voidElements = /AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR/
|
||||
|
||||
|
|
@ -544,7 +545,7 @@ Mithril = m = new function app(window, undefined) {
|
|||
element.addEventListener("click", routeUnobtrusive)
|
||||
}
|
||||
}
|
||||
else if (typeof arguments[0] == "string") {
|
||||
else if (isStr(arguments[0])) {
|
||||
currentRoute = arguments[0]
|
||||
var querystring = isObj(arguments[1]) ? buildQueryString(arguments[1]) : null
|
||||
if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring
|
||||
|
|
|
|||
|
|
@ -1495,6 +1495,36 @@ function testMithril(mock) {
|
|||
})
|
||||
return value == "foo+bar"
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/", {
|
||||
"/": {controller: function() {}, view: function() {return "foo"}},
|
||||
"/test22": {controller: function() {}, view: function() {return "bar"}}
|
||||
})
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
m.route(String("/test22/"))
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return mock.location.search == "?/test22/" && root.childNodes[0].nodeValue === "bar"
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
mock.location.search = "?"
|
||||
|
||||
var root = mock.document.createElement("div")
|
||||
m.route.mode = "search"
|
||||
m.route(root, "/", {
|
||||
"/": {controller: function() {}, view: function() {return "foo"}},
|
||||
"/test23": {controller: function() {}, view: function() {return "bar"}}
|
||||
})
|
||||
mock.requestAnimationFrame.$resolve()
|
||||
m.route(new String("/test23/"))
|
||||
mock.requestAnimationFrame.$resolve() //teardown
|
||||
return mock.location.search == "?/test23/" && root.childNodes[0].nodeValue === "bar"
|
||||
})
|
||||
//end m.route
|
||||
|
||||
//m.prop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue