Assert that tree exists, fix tests (#358)

* assert that tree exists, fix tests

* make assertions more helpful
This commit is contained in:
Tim Wisniewski
2016-12-22 06:55:36 -05:00
committed by GitHub
parent ff1073a664
commit 3b5740c00e
4 changed files with 12 additions and 20 deletions
+2
View File
@@ -64,6 +64,8 @@ function choo (opts) {
const state = _store.state({state: {}})
const tree = _router(state.location.href, state)
assert.ok(tree, 'choo.start: the router should always return a valid DOM node')
assert.equal(typeof tree, 'object', 'choo.start: the router should always return a valid DOM node')
_rootNode = tree
tree.done = done
+2
View File
@@ -16,6 +16,7 @@ test('freeze (default)', function (t) {
t.equal(state.foo, 'bar', 'cannot modify property')
state.bar = 'baz'
t.equal(state.bar, undefined, 'cannot add property')
return document.createElement('div')
}])
app.start()
@@ -36,6 +37,7 @@ test('noFreeze', function (t) {
t.equal(state.foo, '', 'can modify property')
state.bar = 'baz'
t.equal(state.bar, 'baz', 'can add property')
return document.createElement('div')
}])
app.start()
+1 -1
View File
@@ -12,7 +12,7 @@ test('rehydration', function (t) {
const node = html`
<section id="app-root">
<div id="app-root">Hello squirrel!</span>
<div>Hello squirrel!</span>
</section>
`
+7 -19
View File
@@ -125,6 +125,7 @@ test('routing', function (t) {
app.router('/', [
['/', function () {
t.pass('rendered')
return document.createElement('div')
}]
])
@@ -139,7 +140,10 @@ test('routing', function (t) {
})
const app = choo({ href: false })
app.router(['/', () => t.pass('rendered')])
app.router(['/', function () {
t.pass('rendered')
return document.createElement('div')
}])
app.start()
})
@@ -152,30 +156,14 @@ test('routing', function (t) {
app.router({ default: '/users/123' }, [
['/users', [
['/:user', function (state) {
t.deepEqual(state.params, {user: '123'})
t.deepEqual(state.location.params, {user: '123'})
return document.createElement('div')
}]
]]
])
app.start()
})
t.test('prev.params always exists', function (t) {
t.plan(1)
const choo = require('../..')
const app = choo()
app.router('/users/123', (route) => [
route('/users', [
route('/:user', function (state, prev) {
t.ok(prev.params)
})
])
])
app.start()
})
})
function resetLocation () {