]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: check beforeEnter, same component
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 2 May 2019 20:41:09 +0000 (22:41 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 2 May 2019 20:41:09 +0000 (22:41 +0200)
__tests__/guards/route-beforeEnter.spec.js

index 76532b0a9a617d79a912defcc3877c6e82dba3e2..f1583eb24d5fc653090ba287847f2c609a32a0c3 100644 (file)
@@ -23,6 +23,7 @@ const beforeEnter = jest.fn()
 /** @type {import('../../src/types').RouteRecord[]} */
 const routes = [
   { path: '/', component: Home },
+  { path: '/home', component: Home, beforeEnter },
   { path: '/foo', component: Foo },
   {
     path: '/guard/:n',
@@ -49,6 +50,15 @@ describe('beforeEnter', () => {
         expect(beforeEnter).toHaveBeenCalledTimes(1)
       })
 
+      it('calls beforeEnter different records, same component', async () => {
+        const router = createRouter({ routes })
+        beforeEnter.mockImplementationOnce(noGuard)
+        await router.push('/')
+        expect(beforeEnter).not.toHaveBeenCalled()
+        await router[navigationMethod]('/home')
+        expect(beforeEnter).toHaveBeenCalledTimes(1)
+      })
+
       it('does not call beforeEnter guard if we were already on the page', async () => {
         const router = createRouter({ routes })
         beforeEnter.mockImplementation(noGuard)