diff --git a/index.js b/index.js index 03eb04b..72cf731 100644 --- a/index.js +++ b/index.js @@ -195,7 +195,7 @@ Choo.prototype.toString = function (location, state) { this._matchRoute(location) var html = this._prerender(this.state) assert.ok(html, 'choo.toString: no valid value returned for the route ' + location) - return html.toString() + return typeof html.outerHTML === 'string' ? html.outerHTML : html.toString() } Choo.prototype._matchRoute = function (locationOverride) { diff --git a/package.json b/package.json index 3eaa0cb..7dddfd0 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "bundle-collapser": "^1.2.1", "dependency-check": "^2.8.0", "discify": "^1.6.0", + "hyperscript": "^2.0.2", "pretty-bytes-cli": "^2.0.0", "spok": "^0.8.1", "standard": "^10.0.0", diff --git a/test.js b/test.js index e3b85f3..cb74854 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,11 @@ var tape = require('tape') +var h = require('hyperscript') var html = require('./html') var raw = require('./html/raw') var choo = require('./') -tape('should render on the server', function (t) { +tape('should render on the server with bel', function (t) { var app = choo() app.route('/', function (state, emit) { var strong = 'Hello filthy planet' @@ -17,3 +18,14 @@ tape('should render on the server', function (t) { t.equal(res.toString().trim(), exp, 'result was OK') t.end() }) + +tape('should render on the server with hyperscript', function (t) { + var app = choo() + app.route('/', function (state, emit) { + return h('p', h('strong', 'Hello filthy planet')) + }) + var res = app.toString('/') + var exp = '

Hello filthy planet

' + t.equal(res.toString().trim(), exp, 'result was OK') + t.end() +})