more tests

This commit is contained in:
Leo Horie 2016-05-24 23:16:43 -04:00
parent a2c01d1d96
commit e7420e72e1
14 changed files with 596 additions and 215 deletions

View file

@ -8,7 +8,7 @@ module.exports = function() {
var routes = {}
var callback = "callback"
var serverErrorHandler = function() {
return {status: 500, responseText: "server error"}
return {status: 500, responseText: "server error, most likely the URL was not defined"}
}
var $window = {

View file

@ -275,8 +275,7 @@ module.exports = function() {
get: function() {
var options = getOptions(this.parentNode)
var index = options.indexOf(this)
if (index > -1) return index === this.parentNode.selectedIndex
return false
return index === this.parentNode.selectedIndex
},
set: function(value) {
if (value) {

View file

@ -114,10 +114,10 @@ module.exports = function() {
},
set origin(value) {
console.warn("Origin is writable but ignored")
//origin is writable but ignored
},
set host(value) {
console.warn("Host is writable but ignored in Chrome")
//host is writable but ignored in Chrome
},
set href(value) {
var url = getURL()
@ -160,7 +160,6 @@ module.exports = function() {
}
},
},
scrollTo: function(x, y) {},
onpopstate: null,
onhashchange: null,
onunload: null,

View file

@ -345,6 +345,13 @@ o.spec("domMock", function() {
o(div.attributes["id"].nodeValue).equals("[object Object]")
})
o("setting via attributes map stringifies", function() {
var div = $document.createElement("div")
div.setAttribute("id", "a")
div.attributes["id"].nodeValue = 123
o(div.attributes["id"].nodeValue).equals("123")
})
})
o.spec("setAttributeNS", function() {
@ -681,10 +688,16 @@ o.spec("domMock", function() {
var option1 = $document.createElement("option")
option1.appendChild($document.createTextNode("a"))
var option2 = $document.createElement("option")
option2.appendChild($document.createTextNode("b"))
select.appendChild(option1)
select.appendChild(option2)
o(select.value).equals("a")
o(select.selectedIndex).equals(0)
o(select.childNodes[0].selected).equals(true)
o(select.childNodes[0].value).equals("a")
o(select.childNodes[1].value).equals("b")
})
o("value defaults to invalid if no options", function() {
var select = $document.createElement("select")
@ -708,6 +721,29 @@ o.spec("domMock", function() {
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("setting valid value works with optgroup", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
var option3 = $document.createElement("option")
option3.setAttribute("value", "c")
var optgroup = $document.createElement("optgroup")
optgroup.appendChild(option1)
optgroup.appendChild(option2)
select.appendChild(optgroup)
select.appendChild(option3)
select.value = "b"
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("setting valid selectedIndex works", function() {
var select = $document.createElement("select")
@ -740,6 +776,23 @@ o.spec("domMock", function() {
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("unsetting option[selected] works", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.childNodes[1].selected = true
select.childNodes[1].selected = false
o(select.value).equals("a")
o(select.selectedIndex).equals(0)
})
o("setting invalid value yields a selectedIndex of -1 and value of empty string", function() {
var select = $document.createElement("select")

View file

@ -156,6 +156,65 @@ o.spec("pushStateMock", function() {
o($window.location.hash).equals("#b")
})
})
o.spec("set pathname", function() {
o("changes url on location.pathname change", function() {
var old = $window.location.href
$window.location.pathname = "/a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
o($window.location.pathname).equals("/a")
})
})
o.spec("set protocol", function() {
o("setting protocol throws", function(done) {
var old = $window.location.href
try {
$window.location.protocol = "https://"
}
catch (e) {
done()
}
})
})
o.spec("set port", function() {
o("setting origin changes href", function() {
var old = $window.location.href
$window.location.port = "81"
o(old).equals("http://localhost/")
o($window.location.port).equals("81")
o($window.location.href).equals("http://localhost:81/")
})
})
o.spec("set hostname", function() {
o("setting hostname changes href", function() {
var old = $window.location.href
$window.location.hostname = "127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.hostname).equals("127.0.0.1")
o($window.location.href).equals("http://127.0.0.1/")
})
})
o.spec("set origin", function() {
o("setting origin is ignored", function() {
var old = $window.location.href
$window.location.origin = "http://127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.origin).equals("http://localhost")
})
})
o.spec("set host", function() {
o("setting host is ignored", function() {
var old = $window.location.href
$window.location.host = "http://127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.host).equals("localhost")
})
})
o.spec("pushState", function() {
o("changes url on pushstate", function() {
var old = $window.location.href