test: render:context hook

This commit is contained in:
Clark Du 2018-05-03 20:49:37 +01:00
parent 7514db73b2
commit 25d752630a
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
2 changed files with 14 additions and 4 deletions

View File

@ -2,21 +2,26 @@ export default function () {
let ctr = 1 let ctr = 1
// Add hook for module // Add hook for module
this.nuxt.hook('modules:done', (moduleContainer) => { this.nuxt.hook('modules:done', moduleContainer => {
this.nuxt.__module_hook = moduleContainer && ctr++ this.nuxt.__module_hook = moduleContainer && ctr++
}) })
// Add hook for renderer // Add hook for renderer
this.nuxt.hook('render:done', (renderer) => { this.nuxt.hook('render:done', renderer => {
this.nuxt.__renderer_hook = renderer && ctr++ this.nuxt.__renderer_hook = renderer && ctr++
}) })
// Get data before data sent to client
this.nuxt.hook('render:context', data => {
this.nuxt.__render_context = data
})
// Add hook for build // Add hook for build
this.nuxt.hook('build:done', (builder) => { this.nuxt.hook('build:done', builder => {
this.nuxt.__builder_hook = builder && ctr++ this.nuxt.__builder_hook = builder && ctr++
}) })
this.nuxt.hook('build:done', (builder) => { this.nuxt.hook('build:done', builder => {
this.nuxt.__builder_plugin = builder && ctr++ this.nuxt.__builder_plugin = builder && ctr++
}) })
} }

View File

@ -53,6 +53,11 @@ describe('module', () => {
expect(response).toBe('Use external middleware') expect(response).toBe('Use external middleware')
}) })
test('Hooks - render context', async () => {
await nuxt.renderRoute('/render-context')
expect(nuxt.__render_context).toBeTruthy()
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
afterAll(async () => { afterAll(async () => {
await nuxt.close() await nuxt.close()