-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add example of mocking
vue-router
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
3 changes: 3 additions & 0 deletions
3
examples/app-vitest-full/tests/nuxt/__snapshots__/mock-vue-router.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
examples/app-vitest-full/tests/nuxt/mock-vue-router.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |