-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 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,41 @@ | ||
import { mockWarn } from 'jest-mock-warn' | ||
import { createMemoryHistory, createRouter } from '../src' | ||
import { defineComponent } from 'vue' | ||
|
||
let component = defineComponent({}) | ||
|
||
describe('warnings', () => { | ||
mockWarn() | ||
it('warns on missing name and path for redirect', async () => { | ||
const history = createMemoryHistory() | ||
const router = createRouter({ | ||
history, | ||
routes: [ | ||
{ path: '/', component }, | ||
{ path: '/redirect', redirect: { params: { foo: 'f' } } }, | ||
], | ||
}) | ||
await router.push('/redirect').catch(() => {}) | ||
expect('Invalid redirect found').toHaveBeenWarned() | ||
}) | ||
|
||
it('warns when resolving a route with path and params', async () => { | ||
const history = createMemoryHistory() | ||
const router = createRouter({ | ||
history, | ||
routes: [{ path: '/:p', name: 'p', component }], | ||
}) | ||
router.resolve({ path: '/', params: { p: 'p' } }) | ||
expect('Path "/" was passed with params').toHaveBeenWarned() | ||
}) | ||
|
||
it('does not warn when resolving a route with path, params and name', async () => { | ||
const history = createMemoryHistory() | ||
const router = createRouter({ | ||
history, | ||
routes: [{ path: '/:p', name: 'p', component }], | ||
}) | ||
router.resolve({ path: '/p', name: 'p', params: { p: 'p' } }) | ||
expect('Path "/" was passed with params').not.toHaveBeenWarned() | ||
}) | ||
}) |
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