Add tests
This commit is contained in:
@@ -42,3 +42,33 @@ tape("test switchesSelectors", function(t) {
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape("test switchesSelectors when number of elements don't match", function(t) {
|
||||
var newTempDoc = document.implementation.createHTMLDocument()
|
||||
var originalTempDoc = document.implementation.createHTMLDocument()
|
||||
|
||||
// a div container is used because swapping the containers
|
||||
// will generate a new element, so things get weird
|
||||
// using "body" generates a lot of testling cruft that I don't
|
||||
// want so let's avoid that
|
||||
var container = originalTempDoc.createElement("div")
|
||||
container.innerHTML = "<p>Original text</p><span>No change</span>"
|
||||
originalTempDoc.body.appendChild(container)
|
||||
|
||||
var container2 = newTempDoc.createElement("div")
|
||||
container2.innerHTML = "<p>New text</p><p>More new text</p><span>New span</span>"
|
||||
newTempDoc.body.appendChild(container2)
|
||||
|
||||
var switchSelectorsFn = switchesSelectors.bind(pjax,
|
||||
{}, // switches
|
||||
{}, // switchesOptions
|
||||
["p"], // selectors,
|
||||
newTempDoc, // fromEl
|
||||
originalTempDoc, // toEl,
|
||||
{} // options
|
||||
)
|
||||
|
||||
t.throws(switchSelectorsFn, null, "error was thrown properly since number of elements don't match")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user