tests: Add tests for body scripts

This commit is contained in:
Atinux 2017-11-06 13:49:24 +01:00
parent 07eab4c643
commit 46eac50d87
4 changed files with 12 additions and 0 deletions

View File

@ -69,9 +69,11 @@ test('/store', async t => {
}) })
test('/head', async t => { test('/head', async t => {
const msg = new Promise((resolve) => page.on('console', (msg) => resolve(msg.text)))
await page.nuxt.navigate('/head', true) await page.nuxt.navigate('/head', true)
const metas = await page.$$attr('meta', 'content') const metas = await page.$$attr('meta', 'content')
t.is(await msg, 'Body script!')
t.is(await page.title(), 'My title - Nuxt.js') t.is(await page.title(), 'My title - Nuxt.js')
t.is(await page.$text('h1'), 'I can haz meta tags') t.is(await page.$text('h1'), 'I can haz meta tags')
t.is(metas[0], 'my meta') t.is(metas[0], 'my meta')

View File

@ -55,12 +55,17 @@ test('/store', async t => {
}) })
test('/head', async t => { test('/head', async t => {
stdMocks.use()
const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false }) const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false })
const html = window.document.body.innerHTML const html = window.document.body.innerHTML
const metas = window.document.getElementsByTagName('meta') const metas = window.document.getElementsByTagName('meta')
stdMocks.restore()
const { stdout } = stdMocks.flush()
t.is(stdout[0], 'Body script!\n')
t.is(window.document.title, 'My title - Nuxt.js') t.is(window.document.title, 'My title - Nuxt.js')
t.is(metas[0].getAttribute('content'), 'my meta') t.is(metas[0].getAttribute('content'), 'my meta')
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>')) t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
t.true(html.includes('<script data-n-head="true" src="/body.js" data-body="true">'))
}) })
test('/async-data', async t => { test('/async-data', async t => {

View File

@ -10,6 +10,9 @@ export default {
title: 'My title', title: 'My title',
meta: [ meta: [
{ content: 'my meta' } { content: 'my meta' }
],
script: [
{ src: '/body.js', body: true }
] ]
} }
} }

2
test/fixtures/basic/static/body.js vendored Normal file
View File

@ -0,0 +1,2 @@
/* eslint-disable no-console */
console.log('Body script!')