-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(teach-frontend): 03-测试第一个组件 TheHeader - 测试 useRouter 的策略
- Loading branch information
1 parent
6b5b180
commit 25f51b5
Showing
5 changed files
with
74 additions
and
8 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
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
33 changes: 33 additions & 0 deletions
33
apps/teach-frontend/src/components/header/theHeader.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,33 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { useRouter } from 'vue-router' | ||
import { useGoto } from './theHeader' | ||
|
||
vi.mock('vue-router') | ||
|
||
const pushFn = vi.fn() | ||
vi.mocked(useRouter as () => { push: Function }).mockImplementation(() => { | ||
return { | ||
push: pushFn, | ||
} | ||
}) | ||
|
||
describe('theHeader', () => { | ||
beforeEach(() => { | ||
pushFn.mockClear() | ||
}) | ||
it('should be go to home page', () => { | ||
const { goToHome } = useGoto() | ||
|
||
goToHome() | ||
|
||
expect(pushFn).toBeCalledWith({ name: 'Home' }) | ||
}) | ||
|
||
it('should be go to settings page', () => { | ||
const { goToSettings } = useGoto() | ||
|
||
goToSettings() | ||
|
||
expect(pushFn).toBeCalledWith({ name: 'Settings' }) | ||
}) | ||
}) |
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,27 @@ | ||
import { useRouter } from 'vue-router' | ||
|
||
export function useGoto() { | ||
const router = useRouter() | ||
|
||
function goToHome() { | ||
router.push({ | ||
name: 'Home', | ||
}) | ||
} | ||
|
||
function goToSettings() { | ||
router.push({ | ||
name: 'Settings', | ||
}) | ||
} | ||
|
||
function goToGithub() { | ||
window.open('https://github.com/cuixueshe/dida') | ||
} | ||
|
||
return { | ||
goToHome, | ||
goToSettings, | ||
goToGithub, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25f51b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vue3-dida – ./
vue3-dida-cuixueshe.vercel.app
vue3-dida-eta.vercel.app
vue3-dida-git-main-cuixueshe.vercel.app
dida.cuixueshe.com