-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathvue-router.js
33 lines (24 loc) · 1003 Bytes
/
vue-router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'jest-dom/extend-expect'
import App from './components/Router/App.vue'
import Home from './components/Router/Home.vue'
import About from './components/Router/About.vue'
import { cleanup, render, fireEvent } from '@testing-library/vue'
const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '*', redirect: '/about' }
]
afterEach(cleanup)
test('full app rendering/navigating', async () => {
const { queryByTestId } = render(App, { routes })
// normally I'd use a data-testid, but just wanted to show this is also possible
expect(queryByTestId('location-display')).toHaveTextContent('/')
await fireEvent.click(queryByTestId('about-link'))
expect(queryByTestId('location-display')).toHaveTextContent('/about')
})
test('setting initial route', () => {
const { queryByTestId } = render(App, { routes }, (vue, store, router) => {
router.push('/about')
})
expect(queryByTestId('location-display')).toHaveTextContent('/about')
})