Created
September 12, 2018 02:08
-
-
Save kuroski/4041119f0446bd09b0ebffe35bfa167a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jest.mock('@/guards'); | |
import router from "@/router"; | |
import { guardToken, guardCustom } from "@/guards"; | |
describe("router", () => { | |
it("calls 'guardToken' before each route transition", () => { | |
router.push({ name: 'dashboard' }); | |
expect(guardToken).toHaveBeenCalled(); | |
}); | |
it("uses 'guardCustom' route guard on enter", async () => { | |
const expectedRoutes = [ | |
"dashboard" | |
]; | |
const routes = router.options.routes; | |
const routeWithName = name => route => name === route.name; | |
expectedRoutes.forEach(expectedRoute => { | |
const route = routes.find(routeWithName(expectedRoute)); | |
expect(route.beforeEnter).toEqual(guardDashboardEnabled) | |
expect(route.name).toBe(expectedRoute) | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment