Skip to content

Instantly share code, notes, and snippets.

@kuroski
Created September 12, 2018 02:08
Show Gist options
  • Save kuroski/4041119f0446bd09b0ebffe35bfa167a to your computer and use it in GitHub Desktop.
Save kuroski/4041119f0446bd09b0ebffe35bfa167a to your computer and use it in GitHub Desktop.
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