-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
3 changed files
with
90 additions
and
10 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,45 @@ | ||
import { expect, test } from 'vitest' | ||
import { createRouter } from '@/utilities/createRouter' | ||
import { component } from '@/utilities/testHelpers' | ||
|
||
test('initial route is set', () => { | ||
const root = { | ||
name: 'root', | ||
component, | ||
path: '/', | ||
} | ||
|
||
const { route } = createRouter([root], { | ||
initialUrl: root.path, | ||
}) | ||
|
||
expect(route.matched).toMatchObject(root) | ||
}) | ||
|
||
test('throws error if route is not matched', () => { | ||
expect(() => createRouter([])).toThrowError('not implemented') | ||
}) | ||
|
||
test('updates the route when navigating', async () => { | ||
const first = { | ||
name: 'first', | ||
component, | ||
path: '/first', | ||
} | ||
|
||
const second = { | ||
name: 'second', | ||
component, | ||
path: '/second', | ||
} | ||
|
||
const { push, route } = createRouter([first, second], { | ||
initialUrl: first.path, | ||
}) | ||
|
||
expect(route.matched).toMatchObject(first) | ||
|
||
await push(second.path) | ||
|
||
expect(route.matched).toMatchObject(second) | ||
}) |
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,6 @@ | ||
import { expect, test } from 'vitest' | ||
import { createRouter } from '@/utilities/createRouter' | ||
|
||
test('throws error if initial route is not set', () => { | ||
expect(() => createRouter([])).toThrowError('initialUrl must be set if window.location is unavailable') | ||
}) |
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