From 3b5740c00e952a9c703075e436dc29b07dd4befe Mon Sep 17 00:00:00 2001 From: Tim Wisniewski Date: Thu, 22 Dec 2016 06:55:36 -0500 Subject: [PATCH] Assert that tree exists, fix tests (#358) * assert that tree exists, fix tests * make assertions more helpful --- index.js | 2 ++ tests/browser/freeze.js | 2 ++ tests/browser/rehydration.js | 2 +- tests/browser/routing.js | 26 +++++++------------------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index e146564..ad1e724 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/tests/browser/freeze.js b/tests/browser/freeze.js index 1a2f2fc..cbeb83f 100644 --- a/tests/browser/freeze.js +++ b/tests/browser/freeze.js @@ -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() diff --git a/tests/browser/rehydration.js b/tests/browser/rehydration.js index 9eda527..bee4d1a 100644 --- a/tests/browser/rehydration.js +++ b/tests/browser/rehydration.js @@ -12,7 +12,7 @@ test('rehydration', function (t) { const node = html`
-
Hello squirrel! +
Hello squirrel!
` diff --git a/tests/browser/routing.js b/tests/browser/routing.js index c829cde..03321c0 100644 --- a/tests/browser/routing.js +++ b/tests/browser/routing.js @@ -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 () {