Files
buuh/tests/browser/rehydration.js
T
Ben Drucker e3f715f71b 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.
2016-07-04 16:19:17 -07:00

30 lines
746 B
JavaScript

const test = require('tape')
const onReady = require('document-ready')
const append = require('append-child')
const choo = require('../../')
const view = require('../../html')
test('rehydration', function (t) {
t.plan(2)
const app = choo()
app.router((route) => [
route('/', function (state, prev, send) {
return view`<div id="app-root" onclick=${() => send('test')}>Hello world!</span>`
})
])
var node = document.createElement('div')
node.innerHTML = app.toString('/')
node = node.childNodes[0]
t.on('end', append(node))
app.start('#app-root')
onReady(function () {
t.equal(node.innerHTML, 'Hello world!', 'same content')
t.equal(typeof node.onclick, 'function', 'attaches dom listeners')
})
})