Bug 38201: Mock the router for component testing

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Matt Blenkinsop 2025-07-30 11:44:57 +01:00 committed by Lucas Gass
parent 65fd882fa8
commit bf614927a8
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 26 additions and 7 deletions

View File

@ -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: