2016-07-03 15:08:48 -07:00
|
|
|
const test = require('tape')
|
|
|
|
|
const onReady = require('document-ready')
|
2016-07-04 09:09:43 -07:00
|
|
|
const append = require('append-child')
|
2016-07-03 15:08:48 -07:00
|
|
|
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]
|
2016-07-04 09:09:43 -07:00
|
|
|
t.on('end', append(node))
|
2016-07-03 15:08:48 -07:00
|
|
|
|
|
|
|
|
app.start('#app-root')
|
|
|
|
|
|
|
|
|
|
onReady(function () {
|
|
|
|
|
t.equal(node.innerHTML, 'Hello world!', 'same content')
|
|
|
|
|
t.equal(typeof node.onclick, 'function', 'attaches dom listeners')
|
|
|
|
|
})
|
|
|
|
|
})
|