Skip to content

Commit 837b4f0

Browse files
authored
Merge pull request #21 from testing-library/issue/19-programmatic-routing
Issue/19 programmatic routing
2 parents ba19c89 + 29eed0a commit 837b4f0

File tree

8 files changed

+150
-4
lines changed

8 files changed

+150
-4
lines changed

package-lock.json

+85-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>You are on the about page</div>
3+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div>
3+
<RouterLink
4+
to="/"
5+
data-testid="home-link">
6+
Home
7+
</RouterLink>
8+
<RouterLink
9+
to="/about"
10+
data-testid="about-link">
11+
About
12+
</RouterLink>
13+
<RouterView />
14+
<div data-testid="location-display">{{ $route.fullPath }}</div>
15+
</div>
16+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div>
3+
<div>You are home</div>
4+
<button data-testid="go-to-about" @click="goToAbout">About</button>
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
methods: {
11+
goToAbout () {
12+
this.$router.push('/about')
13+
}
14+
}
15+
}
16+
</script>
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div data-testid="location-display">{{ $route.fullPath }}</div>
3+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template functional>
2+
<div>No match</div>
3+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'jest-dom/extend-expect'
2+
3+
import App from './components/App.vue'
4+
import Home from './components/Home.vue'
5+
import About from './components/About.vue'
6+
7+
import { render, fireEvent } from '../../../../src'
8+
9+
const routes = [
10+
{ path: '/', component: Home },
11+
{ path: '/about', component: About },
12+
{ path: '*', redirect: '/about' }
13+
]
14+
15+
test('navigating programmatically', async () => {
16+
const { queryByTestId } = render(App, { routes })
17+
18+
expect(queryByTestId('location-display')).toHaveTextContent('/')
19+
await fireEvent.click(queryByTestId('go-to-about'))
20+
21+
expect(queryByTestId('location-display')).toHaveTextContent('/about')
22+
})

tests/__tests__/stopwatch.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test('updates component state', async () => {
2424
expect(elapsedTime).toHaveTextContent('0ms')
2525

2626
await fireEvent.click(startButton)
27+
await wait()
2728
await fireEvent.click(startButton)
2829

2930
expect(elapsedTime).not.toHaveTextContent('0ms')

0 commit comments

Comments
 (0)