fix: Sanitize head to use titleTemplate as function

This commit is contained in:
Sébastien Chopin 2017-10-28 23:35:10 +02:00
parent 6c8b5e4714
commit bf72a35634
2 changed files with 9 additions and 3 deletions

View File

@ -15,7 +15,7 @@ layoutsKeys.forEach(function (key, i) { %>
let resolvedLayouts = {}
export default {
head: <%= JSON.stringify(head) %>,
head: <%= serialize(head).replace('titleTemplate(', 'function(') %>,
render(h, props) {
<% if (loading) { %>const loadingEl = h('nuxt-loading', { ref: 'loading' })<% } %>
const layoutEl = h(this.nuxt.err ? 'nuxt' : this.layout, {

View File

@ -13,7 +13,12 @@ let nuxt = null
test.before('Init Nuxt.js', async t => {
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false
dev: false,
head: {
titleTemplate (titleChunk) {
return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js'
}
}
}
nuxt = new Nuxt(options)
await new Builder(nuxt).build()
@ -53,7 +58,7 @@ test('/head', async t => {
const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false })
const html = window.document.body.innerHTML
const metas = window.document.getElementsByTagName('meta')
t.is(window.document.title, 'My title')
t.is(window.document.title, 'My title - Nuxt.js')
t.is(metas[0].getAttribute('content'), 'my meta')
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})
@ -103,6 +108,7 @@ test('/redirect -> check redirected source', async t => {
test('/special-state -> check window.__NUXT__.test = true', async t => {
const window = await nuxt.renderAndGetWindow(url('/special-state'))
t.is(window.document.title, 'Nuxt.js')
t.is(window.__NUXT__.test, true)
})