From: Eduardo San Martin Morote Date: Mon, 28 Jun 2021 15:47:57 +0000 (+0200) Subject: test(e2e): more playground X-Git-Tag: v4.0.11~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a134920d8b85089ae23cb2d387f9824a88bde75;p=thirdparty%2Fvuejs%2Frouter.git test(e2e): more playground --- diff --git a/e2e/suspense/index.ts b/e2e/suspense/index.ts index 0c4ceabe..2989056e 100644 --- a/e2e/suspense/index.ts +++ b/e2e/suspense/index.ts @@ -3,8 +3,17 @@ import { createWebHistory, onBeforeRouteUpdate, onBeforeRouteLeave, + RouterView, + useRoute, } from '../../src' -import { createApp, ref, reactive, defineComponent } from 'vue' +import { + createApp, + ref, + reactive, + defineComponent, + FunctionalComponent, + h, +} from 'vue' const Home = defineComponent({ template: ` @@ -43,13 +52,22 @@ function createTestComponent(key: string, isAsync = false) { logs.value.push(`${key}: setup:leave ${from.fullPath} - ${to.fullPath}`) }) - return isAsync ? delay(100).then(() => ({})) : {} + const route = useRoute() + const shouldFail = !!route.query.fail + + return isAsync + ? delay(100).then(() => + shouldFail ? Promise.reject(new Error('failed')) : {} + ) + : {} }, }) } const Foo = createTestComponent('Foo') const FooAsync = createTestComponent('FooAsync', true) +const PassThroughView: FunctionalComponent = () => h(RouterView) +PassThroughView.displayName = 'RouterView' const webHistory = createWebHistory('/' + __dirname) const router = createRouter({ @@ -64,9 +82,17 @@ const router = createRouter({ path: '/foo-async', component: FooAsync, }, + { + path: '/nested', + component: PassThroughView, + children: [ + { path: 'one', component: createTestComponent('one', true) }, + { path: 'two', component: createTestComponent('two', true) }, + ], + }, ], }) - +const shouldFail = ref(false) const app = createApp({ template: `

Suspense

@@ -78,6 +104,8 @@ updates: {{ state.update }} leaves: {{ state.leave }} + +
{{ logs.join('\\n') }}
@@ -87,19 +115,26 @@ leaves: {{ state.leave }}
  • /foo
  • /foo-async
  • {{ route.fullPath }}
  • +
  • /nested/one
  • +
  • /nested/two
  • - + `, setup() { - return { state, logs } + return { state, logs, log: console.log, shouldFail } }, }) +router.beforeEach(to => { + if (shouldFail.value && !to.query.fail) + return { ...to, query: { ...to.query, fail: 'yes' } } + return +}) app.use(router) window.r = router