mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 13:48:13 +00:00
add unit test
This commit is contained in:
parent
b73ff33136
commit
b99d5660e4
@ -2845,3 +2845,15 @@ describe('namespace access to useNuxtApp', () => {
|
||||
await page.close()
|
||||
})
|
||||
})
|
||||
|
||||
describe('page hook', () => {
|
||||
it('should trigger page:loading:end only once', async () => {
|
||||
const { page, consoleLogs } = await renderPage()
|
||||
await page.goto(url('/page-load-hook'))
|
||||
await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path, '/page-load-hook')
|
||||
const loadingEndLogs = consoleLogs.filter(c => c.text.includes('page:loading:end'))
|
||||
expect(loadingEndLogs.length).toBe(1)
|
||||
|
||||
await page.close()
|
||||
})
|
||||
})
|
||||
|
5
test/fixtures/basic/pages/page-load-hook.vue
vendored
Normal file
5
test/fixtures/basic/pages/page-load-hook.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
Page for hook tests.
|
||||
</div>
|
||||
</template>
|
5
test/fixtures/basic/plugins/page-hook-plugin.ts
vendored
Normal file
5
test/fixtures/basic/plugins/page-hook-plugin.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.hook('page:loading:end', () => {
|
||||
console.log('page:loading:end');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user