Skip to content

Commit

Permalink
feat: add addRouteMiddleware test (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
wattanx authored Jun 23, 2023
1 parent b9c8e40 commit 9b0a98e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions playground/pages/add-route-middleware.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<div>navigate to navigate-target</div>
</template>
<script>
export default defineComponent({
middleware: 'local-middleware'
})
</script>
9 changes: 8 additions & 1 deletion playground/plugins/setup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { onGlobalSetup, ref } from '@nuxtjs/composition-api'

import { defineNuxtPlugin } from '#app'
import { defineNuxtPlugin, addRouteMiddleware, navigateTo } from '#app'

export default defineNuxtPlugin(() => {
const globalsetup = ref('🚧')
onGlobalSetup(() => {
globalsetup.value = '✅'
})

addRouteMiddleware('local-middleware', (to) => {
if (to.path === '/add-route-middleware') {
return navigateTo('/navigation-target')
}
})

return {
provide: {
globalsetup
Expand Down
6 changes: 6 additions & 0 deletions test/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ describe('middleware', () => {
})
expect(res.status).toEqual(401)
})

it('should redirect to navigation-target', async () => {
const html = await $fetch('/add-route-middleware')

expect(html).toContain('Navigated successfully')
})
})

describe('dynamic paths', () => {
Expand Down

0 comments on commit 9b0a98e

Please sign in to comment.