第一个问题是:
无法渲染来自vuetify的v-btn所在的组件。测试开始时,将显示一条警告:
[Vue warn]:无法解析组件:v-btn如果这是一个本机自定义元素,请确保通过compilerOptions. isCustomElement将其从组件解析中排除。at at
之后我们做了自定义render函数:
import { render } from "@testing-library/vue";
import { vuetify } from "./src/vuetify/vuetify";
const customRender = (component, options) => {
return render(component, { ...options, global: { plugins: [vuetify] } });
};
export { customRender as render };
还有一个问题
/var/www/html/node_modules/vuetify/lib/styles/main.css:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){@keyframes v-shake {
^
SyntaxError: Invalid or unexpected token
> 1 | import "vuetify/styles";
| ^
2 | import "@mdi/font/css/materialdesignicons.css";
3 | import { createVuetify } from "vuetify";
4 | import { aliases, mdi } from "vuetify/iconsets/mdi";
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1495:14)
at Object.require (resources/js/plugins/vuetify.js:1:1)
at Object.require (resources/js/components/UI/testing-render.js:3:1)
at Object.require (resources/js/components/UI/AppButton.test.js:1:1)
配置
AppButton.test.js
import { render, screen } from "@testing-library/vue";
import AppButton from "./AppButton.vue";
test("render AppButton", () => {
render(AppButton);
screen.debug();
});
jest.config.js
module.exports = {
testEnvironment: "jsdom",
moduleFileExtensions: ["js", "json", "vue"],
transform: {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "@vue/vue3-jest",
},
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"],
},
};
babel.config.js
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
1条答案
按热度按时间0md85ypi1#
我可以为vuetify 3设置jest。你的渲染功能帮了我很多。