我正在vue中运行画布的单元测试(测试通过)。返回错误console.error node_modules/@vue/test-utils/dist/vue-test-utils.js:1735 [vue-test-utils]: Global error handler detected (Vue.config.errorHandler). Vue Test Utils sets a custom error handler to throw errors thrown by instances. If you want this behavior in your tests, you must remove the global error handler.
我尝试停用错误处理程序,但这似乎不支持?https://v2.vuejs.org/v2/api/#errorHandler如何应用错误消息中的建议?
这里有一个类似的问题:How to disable the "Global error handler detected" warning in vue test utils,但没有有用的答案。
我的测试是使用jest和fabric编写的(对于画布):
import FabricCanvas from './FabricCanvas';
import { fabric } from 'fabric';
import { shallowMount } from '@vue/test-utils';
import PolygonDrawing from "@/components/labeling/editor/drawing/PolygonDrawing";
function getFabricCanvas(): fabric.Canvas {
const wrapper = shallowMount (FabricCanvas);
const canvas = wrapper.get('#main-canvas').html();
return new fabric.Canvas(canvas, {
width: 1024,
height: 1024,
} as any);
}
let fCanvas: fabric.Canvas | undefined;
beforeAll(() => {
fCanvas = getFabricCanvas();
})
test('add a Polygon to the canvas startDrawingPolygon and stopDrawingPolygon', () => {
const polygonDrawing = new PolygonDrawing();
if (fCanvas) {
expect(fCanvas._objects.length).toStrictEqual(0);
}
const objectClass = 'Vehicle';
const shapeType = 'polygon';
let startMousePoint = {x: 200, y: 200};
polygonDrawing.startDrawingPolygon(fCanvas, startMousePoint, objectClass, shapeType);
startMousePoint = {x: 300, y: 300};
polygonDrawing.startDrawingPolygon(fCanvas, startMousePoint, objectClass, shapeType);
startMousePoint = {x: 200, y: 300};
polygonDrawing.startDrawingPolygon(fCanvas, startMousePoint, objectClass, shapeType);
if (fCanvas) {
polygonDrawing.stopDrawingPolygon(fCanvas, shapeType, objectClass);
expect(fCanvas._objects.length).toStrictEqual(1);
}
})
});
画布使用文件FabricCanvas.vue模拟:
<template>
<div id="canvas-container">
<canvas width="1024" height="1024" id="main-canvas"></canvas>
</div>
</template>
<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
@Component
export default class FabricCanvas extends Vue {
}
</script>
<style scoped> </style>
2条答案
按热度按时间sczxawaw1#
感谢@tony19的提示,我找到了解决方案:Elastic有一个名为APM(应用程序性能监控)的插件,它位于我的router/index.js中:
import { ApmVuePlugin } from '@elastic/apm-rum-vue';
这是重复的全局错误处理程序的原因,在测试期间将其停用解决了错误消息。
7jmck4yq2#
在我的项目中,我使用
vue2
与@vitejs/plugin-vue2
和vitest
。我也犯过类似的错误。我通过删除vitest.config.js
中的'threads'-选项修复了它