mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
tests: Add tests for body scripts
This commit is contained in:
parent
07eab4c643
commit
46eac50d87
@ -69,9 +69,11 @@ test('/store', async t => {
|
||||
})
|
||||
|
||||
test('/head', async t => {
|
||||
const msg = new Promise((resolve) => page.on('console', (msg) => resolve(msg.text)))
|
||||
await page.nuxt.navigate('/head', true)
|
||||
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.$text('h1'), 'I can haz meta tags')
|
||||
t.is(metas[0], 'my meta')
|
||||
|
@ -55,12 +55,17 @@ test('/store', async t => {
|
||||
})
|
||||
|
||||
test('/head', async t => {
|
||||
stdMocks.use()
|
||||
const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false })
|
||||
const html = window.document.body.innerHTML
|
||||
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(metas[0].getAttribute('content'), 'my meta')
|
||||
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 => {
|
||||
|
3
test/fixtures/basic/pages/head.vue
vendored
3
test/fixtures/basic/pages/head.vue
vendored
@ -10,6 +10,9 @@ export default {
|
||||
title: 'My title',
|
||||
meta: [
|
||||
{ content: 'my meta' }
|
||||
],
|
||||
script: [
|
||||
{ src: '/body.js', body: true }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
2
test/fixtures/basic/static/body.js
vendored
Normal file
2
test/fixtures/basic/static/body.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/* eslint-disable no-console */
|
||||
console.log('Body script!')
|
Loading…
Reference in New Issue
Block a user