]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add navigation type tests
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Sep 2020 08:27:55 +0000 (10:27 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Sep 2020 08:27:55 +0000 (10:27 +0200)
test-dts/navigationGuards.test-d.ts [new file with mode: 0644]

diff --git a/test-dts/navigationGuards.test-d.ts b/test-dts/navigationGuards.test-d.ts
new file mode 100644 (file)
index 0000000..66e83da
--- /dev/null
@@ -0,0 +1,37 @@
+import { createRouter, createWebHistory, expectType } from './index'
+import { NavigationFailure } from 'dist/vue-router'
+
+const router = createRouter({
+  history: createWebHistory(),
+  routes: [],
+})
+
+router.beforeEach((to, from) => {
+  return { path: '/' }
+})
+
+router.beforeEach((to, from) => {
+  return '/'
+})
+
+router.beforeEach((to, from) => {
+  return false
+})
+
+// @ts-expect-error
+router.beforeEach((to, from, next) => {
+  return Symbol('not supported')
+})
+// @ts-expect-error
+router.beforeEach(() => {
+  return Symbol('not supported')
+})
+
+router.beforeEach((to, from, next) => {
+  // @ts-expect-error
+  next(Symbol('not supported'))
+})
+
+router.afterEach((to, from, failure) => {
+  expectType<NavigationFailure | undefined | void>(failure)
+})