vue.jsjestjshtml5-canvasfabricjsvue-test-utils

VueJs how to remove global error handler for testing with vue-test-utils


I am running a unit test for a canvas in vue (test is passing). However i get the error 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.

I tried deactivating the error handler , but this seems not to be supported? https://v2.vuejs.org/v2/api/#errorHandler How can I apply the suggestion from the error message?

There is a similar question here: How to disable the "Global error handler detected" warning in vue test utils, but no useful answer.

My test is written using jest and fabric (for the canvas):

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);
    }
  })
});

The canvas is mocked using the file 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>


Solution

  • Thanks to the hints by @tony19 I found the solution: There was a plugin from Elastic called APM (Application Performace Monitoring) that was inside my router/index.js: import { ApmVuePlugin } from '@elastic/apm-rum-vue';

    This was reponsible for the duplicate Global error handler, deactivating it during tests solved the error message.