function canvasMockify(html = "") {
  // Start of message that we want to suppress.
  const consoleErrorMessageToSuppress =
    "Error: Not implemented: HTMLCanvasElement.prototype.getContext" +
    " (without installing the canvas npm package)";

  // Override default virtual console of jsdom
  const virtualConsole = new jsdom.VirtualConsole();

  // Set up a simple 'mock' console output. Only 'error' needs to be overridden
  const myConsole = {
    error: (message) => {
      if (message.indexOf(consoleErrorMessageToSuppress) === 0) {
        //console.error('all is well');
      } else {
        // All other messages pass through
        console.error(consoleErrorMessageToSuppress);
      }
    },
  };

  // Using the global catch instead of specific event handler, because I couldn't get them to work
  virtualConsole.sendTo(myConsole);

  const cleanupFunction = jsdom_global(html, {
    skipWindowCheck: true,
    virtualConsole: virtualConsole,
  });

  overrideCreateElement(window); // The actual initialization of canvas-mock

  overrideCreateElementNS(window);

  return cleanupFunction;
}
Initialize the mock, jsdom and jsdom_global for unit test usage.

Suppresses a warning from `jsdom` on usage of `getContext()`. A mock definition is added for
it, so the message is not relevant.
@param {string} [html]  html definitions which should be added to the jsdom definition
@returns {Function}  function to call in after(), to clean up for `jsdom_global`