Skip to content

Issue/19 programmatic routing #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 85 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>You are on the about page</div>
</template>
16 changes: 16 additions & 0 deletions tests/__tests__/router/programmatic-routing/components/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<div>
<RouterLink
to="/"
data-testid="home-link">
Home
</RouterLink>
<RouterLink
to="/about"
data-testid="about-link">
About
</RouterLink>
<RouterView />
<div data-testid="location-display">{{ $route.fullPath }}</div>
</div>
</template>
17 changes: 17 additions & 0 deletions tests/__tests__/router/programmatic-routing/components/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div>
<div>You are home</div>
<button data-testid="go-to-about" @click="goToAbout">About</button>
</div>
</template>

<script>
export default {
methods: {
goToAbout () {
this.$router.push('/about')
}
}
}
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div data-testid="location-display">{{ $route.fullPath }}</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template functional>
<div>No match</div>
</template>
22 changes: 22 additions & 0 deletions tests/__tests__/router/programmatic-routing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'jest-dom/extend-expect'

import App from './components/App.vue'
import Home from './components/Home.vue'
import About from './components/About.vue'

import { render, fireEvent } from '../../../../src'

const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '*', redirect: '/about' }
]

test('navigating programmatically', async () => {
const { queryByTestId } = render(App, { routes })

expect(queryByTestId('location-display')).toHaveTextContent('/')
await fireEvent.click(queryByTestId('go-to-about'))

expect(queryByTestId('location-display')).toHaveTextContent('/about')
})
1 change: 1 addition & 0 deletions tests/__tests__/stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('updates component state', async () => {
expect(elapsedTime).toHaveTextContent('0ms')

await fireEvent.click(startButton)
await wait()
await fireEvent.click(startButton)

expect(elapsedTime).not.toHaveTextContent('0ms')
Expand Down