add unit test

This commit is contained in:
Peter Buglavecz 2024-10-10 21:43:14 +02:00
parent b73ff33136
commit b99d5660e4
3 changed files with 22 additions and 0 deletions

View File

@ -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()
})
})

View File

@ -0,0 +1,5 @@
<template>
<div>
Page for hook tests.
</div>
</template>

View File

@ -0,0 +1,5 @@
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('page:loading:end', () => {
console.log('page:loading:end');
});
});