Clean up all DOM nodes when tests end

As the test suite grows it's bad for debugging to leak tons of elements
onto document.body. In order to concisely append/remove on the tests'
"end" event, we need to make sure the root tagName doesn't change. If it
does, the `tree` returned from `app.start` will no longer be the root
node and the removal fn will throw.
This commit is contained in:
Ben Drucker
2016-07-04 16:19:17 -07:00
parent 1e006f3716
commit e3f715f71b
5 changed files with 12 additions and 7 deletions
+5 -4
View File
@@ -1,6 +1,7 @@
const test = require('tape')
const Event = require('geval/event')
const proxyquire = require('proxyquire')
const append = require('append-child')
const view = require('../../html')
test('routing', function (t) {
@@ -39,7 +40,7 @@ test('routing', function (t) {
])
const tree = app.start()
document.body.appendChild(tree)
t.on('end', append(tree))
t.equal(tree.innerHTML.trim(), 'Open')
tree.onclick()
@@ -54,7 +55,7 @@ test('routing', function (t) {
function childView (state, prev, send) {
t.equal(state.user, 1)
return view`<div>${state.user}</div>`
return view`<button>${state.user}</button>`
}
})
@@ -92,7 +93,7 @@ test('routing', function (t) {
])
const tree = app.start({hash: true})
document.body.appendChild(tree)
t.on('end', append(tree))
tree.onclick()
@@ -106,7 +107,7 @@ test('routing', function (t) {
function childView (state, prev, send) {
t.equal(state.user, 1)
return view`<div>${state.user}</div>`
return view`<button>${state.user}</button>`
}
})