everything vue test
1.0.0
Everything I should know to test vue components.I will use vue2, vue3, elementUI and ant-design-vue to build some TodoApp.Then use cypress and vue test utils to test them.
Visual
and Behavioral
cy.mount(TodoItem, {
propsData: {
label: "下班",
isDone: false,
},
}).then(({ wrapper }) => {
return cy.wrap(wrapper).as("vue");
});
cy.get("@vue").then((current: any) => {
current.setProps({
isDone: true,
});
});
// cypress/support/component.ts
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Cypress.Commands.add("mount", (component, args = {}) => {
Vue.use(ElementUI);
return mount(component as any, args);
});
分两种情况
// cypress/support/component.ts
import Antdv from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
Cypress.Commands.add("mount", (component, args = {}) => {
args.global = args.global || {};
args.global.plugins = args.global.plugins || [];
args.global.plugins.push(Antdv);
return mount(component as any, args);
});
// cypress/support/component.ts
import { createPinia, setActivePinia } from "pinia";
setActivePinia(createPinia());
// cypress/support/component.ts
Cypress.Commands.add("mount", (component: any, args: any = {}) => {
args.global.mocks = args.global.mocks || {};
args.global.mocks.$xss = xss;
});