toString: support rehydration

This commit is contained in:
Yoshua Wuyts
2016-05-24 02:10:17 +09:00
parent 80dca262ad
commit 60665f2a71
8 changed files with 159 additions and 33 deletions
+28 -1
View File
@@ -30,7 +30,7 @@ tape('should render on the server', function (t) {
t.equal(html, expected, 'strings are equal')
})
t.test('should extend existing models', function (t) {
t.test('should extend flat existing models', function (t) {
t.plan(1)
const app = choo()
@@ -47,6 +47,33 @@ tape('should render on the server', function (t) {
t.equal(html, expected, 'strings are equal')
})
t.test('should extend namespaced existing models', function (t) {
t.plan(1)
const app = choo()
app.model({
namespace: 'hello',
state: { bin: 'baz', beep: 'boop' }
})
app.router((route) => [
route('/', function (params, state) {
return choo.view`
<h1>${state.hello.foo} ${state.hello.bin} ${state.hello.beep}</h1>
`
})
])
const state = {
hello: {
foo: 'bar!',
beep: 'beep'
}
}
const html = app.toString('/', state)
const expected = '<h1>bar! baz beep</h1>'
t.equal(html, expected, 'strings are equal')
})
t.test('should throw if called without route', function (t) {
t.plan(1)