Cypress repo中有一个使用 vue 路由器的示例应用程序。
这是他们设置的方式
import PizzaShop from './PizzaShop' // component to test
import router from './PizzaShop/router' // router config from app
import { mountCallback } from '@cypress/vue' // extended mount function
describe('Vue Router - Pizza Shop', () => {
// your component will be a child of the simple wrapper below
const extensions = {
plugins: [router],
components: {
PizzaShop,
},
}
// wrapper into which router is injected
const template = '<router-view />'
// initialize a fresh Vue app before each test (equivalent to createLocalVue)
beforeEach(mountCallback({ template, router }, { extensions }))
it('go to order page', () => {
cy.get('button.order').click()
cy.contains('Toppings')
})
并且/PizzaShop/router(但是您的应用程序将拥有自己的路由器代码,因此请替换它)
import { createRouter, createWebHashHistory } from 'vue-router'
import PizzaShop from './index.vue'
import Home from './Home.vue'
import Order from './Order.vue'
export default createRouter({
history: createWebHashHistory(),
routes: [
{
path: '/',
component: PizzaShop,
children: [
{ path: '', name: 'home', component: Home },
{ path: 'order/:preset?', name: 'order', component: Order },
],
},
],
})