Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 96c0c2d

Browse files
authored
feat: allow passing instantiated Vue Router (#239)
1 parent 9d63d71 commit 96c0c2d

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

‎src/__tests__/vue-router.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import '@testing-library/jest-dom'
22
import {render, fireEvent} from '@testing-library/vue'
3+
import VueRouter from 'vue-router'
34

45
import App from './components/Router/App.vue'
56
import Home from './components/Router/Home.vue'
@@ -32,3 +33,15 @@ test('setting initial route', () => {
3233

3334
expect(getByTestId('location-display')).toHaveTextContent('/about')
3435
})
36+
37+
test('can render with an instantiated Vuex store', async () => {
38+
// Instantiate a router with only one route
39+
const instantiatedRouter = new VueRouter({
40+
routes: [{path: '/special-path', component: Home}],
41+
})
42+
43+
render(App, {routes: instantiatedRouter}, (vue, store, router) => {
44+
expect(router.getRoutes()).toHaveLength(1)
45+
expect(router.getRoutes()[0].path).toEqual('/special-path')
46+
})
47+
})

‎src/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function render(
3939
const VueRouter = requiredRouter.default || requiredRouter
4040
localVue.use(VueRouter)
4141

42-
router = new VueRouter({routes})
42+
router = routesinstanceofVueRouter ? routes : new VueRouter({routes})
4343
}
4444

4545
if (configurationCb && typeof configurationCb === 'function') {

‎types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface RenderOptions<V extends Vue, S = {}>
4141
extends Omit<ThisTypedMountOptions<V>, 'store' | 'props'> {
4242
props?: object
4343
store?: StoreOptions<S>
44-
routes?: RouteConfig[]
44+
routes?: RouteConfig[]|Router
4545
container?: Element
4646
baseElement?: Element
4747
}

‎types/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
3+
import VueRouter from 'vue-router'
34
import {render, fireEvent, screen, waitFor} from '@testing-library/vue'
45

56
declare const elem: Element
@@ -152,6 +153,14 @@ export function testInstantiatedStore() {
152153
})
153154
}
154155

156+
export function testInstantiatedRouter() {
157+
render(SomeComponent, {
158+
routes: new VueRouter({
159+
routes: [{path: '/', name: 'home', component: SomeComponent}],
160+
}),
161+
})
162+
}
163+
155164
/*
156165
eslint
157166
testing-library/prefer-explicit-assert: "off",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /