From bf614927a88bf13ddd051e631b4e3972873579d6 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 30 Jul 2025 11:44:57 +0100 Subject: [PATCH] Bug 38201: Mock the router for component testing Signed-off-by: Michaela Sieber Signed-off-by: Jonathan Druart Signed-off-by: Lucas Gass --- t/cypress/support/component.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/t/cypress/support/component.ts b/t/cypress/support/component.ts index 1a01521706..06278124a0 100644 --- a/t/cypress/support/component.ts +++ b/t/cypress/support/component.ts @@ -21,6 +21,7 @@ import { mount } from "cypress/vue"; import i18n from "@koha-vue/i18n"; +import { createWebHistory, createRouter } from "vue-router"; // Augment the Cypress namespace to include type definitions for // your custom command. @@ -35,13 +36,31 @@ import i18n from "@koha-vue/i18n"; // }; Cypress.Commands.add("mount", (component, options = {}) => { - return mount(component, { - global: { - plugins: [i18n, ...(options.global?.plugins || [])], - ...options.global, - }, - ...options, - }); + options.global = options.global || {}; + options.global.plugins = options.global.plugins || []; + + if (!options.router) { + options.router = createRouter({ + routes: [ + { + path: "/:pathMatch(.*)*", + name: "home", + children: [], + }, + ], + history: createWebHistory(), + }); + options.router.beforeEach((to, from, next) => { + if (!to.matched.length) next(); + }); + options.global.plugins.push({ + install(app) { + app.use(options.router); + }, + }); + } + options.global.plugins.push(i18n); + return mount(component, options); }); // Example use: