Match route before init stores (#698)

This commit is contained in:
Carl Törnqvist
2019-06-12 13:42:18 +02:00
committed by GitHub
parent b373c7ee06
commit a871818d32
3 changed files with 43 additions and 2 deletions
+21
View File
@@ -191,6 +191,27 @@ tape('state should include location on render', function (t) {
app.mount(container)
})
tape('state should include location on store init', function (t) {
t.plan(6)
var app = choo()
var container = init('/foo/bar/file.txt?bin=baz')
app.use(store)
app.route('/:first/:second/*', function (state, emit) {
return html`<div></div>`
})
app.mount(container)
function store (state, emit) {
var params = { first: 'foo', second: 'bar', wildcard: 'file.txt' }
t.equal(state.href, '/foo/bar/file.txt', 'state has href')
t.equal(state.route, ':first/:second/*', 'state has route')
t.ok(state.hasOwnProperty('params'), 'state has params')
t.deepEqual(state.params, params, 'params match')
t.ok(state.hasOwnProperty('query'), 'state has query')
t.deepEqual(state.query, { bin: 'baz' }, 'query match')
}
})
tape('state should include title', function (t) {
t.plan(3)
document.title = 'foo'
+20
View File
@@ -185,6 +185,26 @@ tape('state should include location on render', function (t) {
t.end()
})
tape('state should include location on store init', function (t) {
t.plan(6)
var app = choo()
app.use(store)
app.route('/:first/:second/*', function (state, emit) {
return html`<div></div>`
})
app.toString('/foo/bar/file.txt?bin=baz')
function store (state, emit) {
var params = { first: 'foo', second: 'bar', wildcard: 'file.txt' }
t.equal(state.href, '/foo/bar/file.txt', 'state has href')
t.equal(state.route, ':first/:second/*', 'state has route')
t.ok(state.hasOwnProperty('params'), 'state has params')
t.deepEqual(state.params, params, 'params match')
t.ok(state.hasOwnProperty('query'), 'state has query')
t.deepEqual(state.query, { bin: 'baz' }, 'query match')
}
})
tape('state should include cache', function (t) {
t.plan(6)
var app = choo()