|
1 |
| -test.todo('Your test suite must contain at least one test.') |
2 |
| - |
3 |
| -// // Please notice that this example is a draft example on how to test |
4 |
| -// // the router. |
5 |
| -// // Related issue on Vue Test Utils: https://github.com/vuejs/vue-test-utils-next/issues/152 |
6 |
| - |
7 |
| -// import '@testing-library/jest-dom' |
8 |
| -// import {render, fireEvent} from '..' |
9 |
| -// import App from './components/Router/App.vue' |
10 |
| -// import Home from './components/Router/Home.vue' |
11 |
| -// import About from './components/Router/About.vue' |
12 |
| - |
13 |
| -// const routes = [ |
14 |
| -// {path: '/', component: Home}, |
15 |
| -// {path: '/about', component: About}, |
16 |
| -// ] |
17 |
| - |
18 |
| -// test('full app rendering/navigating', async () => { |
19 |
| -// // Notice how we pass a `routes` object to our render function. |
20 |
| -// const {queryByTestId} = render(App, {routes}) |
21 |
| - |
22 |
| -// expect(queryByTestId('location-display')).toHaveTextContent('/') |
23 |
| - |
24 |
| -// await fireEvent.click(queryByTestId('about-link')) |
25 |
| - |
26 |
| -// expect(queryByTestId('location-display')).toHaveTextContent('/about') |
27 |
| -// }) |
28 |
| - |
29 |
| -// test('setting initial route', () => { |
30 |
| -// // The callback function receives three parameters: the Vue instance where |
31 |
| -// // the component is mounted, the store instance (if any) and the router |
32 |
| -// // object. |
33 |
| -// const {queryByTestId} = render(App, {routes}, (vue, store, router) => { |
34 |
| -// router.push('/about') |
35 |
| -// }) |
36 |
| - |
37 |
| -// expect(queryByTestId('location-display')).toHaveTextContent('/about') |
38 |
| -// }) |
| 1 | +// Please notice that this example is a draft example on how to test |
| 2 | +// the router. |
| 3 | +// Related issue on Vue Test Utils: https://github.com/vuejs/vue-test-utils-next/issues/152 |
| 4 | + |
| 5 | +import '@testing-library/jest-dom' |
| 6 | +import {waitFor} from '@testing-library/dom' |
| 7 | +import {render, fireEvent} from '..' |
| 8 | +import App from './components/Router/App.vue' |
| 9 | +import Home from './components/Router/Home.vue' |
| 10 | +import About from './components/Router/About.vue' |
| 11 | + |
| 12 | +const routes = [ |
| 13 | + {path: '/', component: Home}, |
| 14 | + {path: '/about', component: About}, |
| 15 | +] |
| 16 | + |
| 17 | +test('full app rendering/navigating', async () => { |
| 18 | + // Notice how we pass a `routes` object to our render function. |
| 19 | + const {findByText, getByText, getByTestId} = render(App, {routes}) |
| 20 | + |
| 21 | + // Vue Router navigation is async, so we need to wait until the |
| 22 | + // initial render happens |
| 23 | + expect(await findByText('You are home')).toBeInTheDocument() |
| 24 | + |
| 25 | + await fireEvent.click(getByTestId('about-link')) |
| 26 | + |
| 27 | + // Same thing hereVue Router navigation is async, so we need to wait until the |
| 28 | + // navigation happens |
| 29 | + await waitFor(() => |
| 30 | + expect(getByTestId('location-display')).toHaveTextContent('/about'), |
| 31 | + ) |
| 32 | + |
| 33 | + expect(getByText('You are on the about page')).toBeInTheDocument() |
| 34 | +}) |
0 commit comments