mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
test: call created and mounted only once with spa and custom layout
This commit is contained in:
parent
68680ee65a
commit
7f8671f1de
7
test/fixtures/spa/layouts/default.vue
vendored
Normal file
7
test/fixtures/spa/layouts/default.vue
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<div>
|
||||
Default layout
|
||||
<br>
|
||||
<nuxt/>
|
||||
</div>
|
||||
</template>
|
4
test/fixtures/spa/pages/custom.vue
vendored
4
test/fixtures/spa/pages/custom.vue
vendored
@ -5,8 +5,10 @@
|
||||
<script>
|
||||
export default {
|
||||
layout: 'custom',
|
||||
created() {
|
||||
console.log('created') // eslint-disable-line no-console
|
||||
},
|
||||
mounted() {
|
||||
window.customMounted = (+window.customMounted) + 1
|
||||
console.log('mounted') // eslint-disable-line no-console
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import test from 'ava'
|
||||
import stdMocks from 'std-mocks'
|
||||
import { Nuxt, Builder } from '../index.js'
|
||||
|
||||
let nuxt = null
|
||||
@ -35,6 +36,17 @@ test('/custom (not default layout)', async t => {
|
||||
t.false(head.includes('src="/_nuxt/layouts/default.'))
|
||||
})
|
||||
|
||||
test('/custom (call mounted and created once)', async t => {
|
||||
stdMocks.use()
|
||||
await renderRoute('/custom')
|
||||
stdMocks.restore()
|
||||
const output = stdMocks.flush()
|
||||
const creates = output.stdout.filter(value => value === 'created\n')
|
||||
t.true(creates.length === 1)
|
||||
const mounts = output.stdout.filter(value => value === 'mounted\n')
|
||||
t.true(mounts.length === 1)
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
nuxt.close()
|
||||
|
Loading…
Reference in New Issue
Block a user