Skip to content

Commit

Permalink
test: add example of mocking vue-router
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jan 28, 2024
1 parent b90c61e commit e293cea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/app-vitest-full/pages/router/route.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { useRoute } from 'vue-router'
const route = useRoute()
</script>

<template>
<div>Index page, path: {{ route.path }}</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Index > should render correctly 1`] = `"<div>Index page, path: /123</div>"`;
19 changes: 19 additions & 0 deletions examples/app-vitest-full/tests/nuxt/mock-vue-router.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it, vi } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import Index from '~/pages/router/route.vue'

vi.mock('vue-router', () => ({
useRoute: vi.fn(() => ({
meta: {},
path: '/123',
query: {},
})),
}))

describe('Index', async () => {
const wrapper = await mountSuspended(Index)

it('should render correctly', () => {
expect(wrapper.html()).toMatchSnapshot()
})
})

0 comments on commit e293cea

Please sign in to comment.