Currently, I am in the process of setting up a unit test case for a function within a TypeScript class. This particular class relies on svg.js. However, when attempting to run the unit test with Jest, an error is thrown stating that SVG.extend or SVG is not recognized as a function.
We have attempted different approaches in the jest.config.js file by configuring the testEnvironment to be node to jsdom.
The TypeScript code snippet looks like this: import SVG from 'svg.js';
export class DrawManager {
private static _drawingStage : SVG.Nested|undefined;
private static _canvas : SVG.Doc|undefined;
}
static start(div: string) {
this._canvas = SVG(div)
this._drawingStage = this._canvas.nested();
}
The code for the unit test is as follows:
import { DrawManager } from './drawmanager';
describe('Test for Draw Manager', () => {
it('should execute the task loader method successfully', () => {
DrawManager.start('drawing');
});
});
Our goal is to have the test case pass without encountering any issues related to SVG dependencies and ensure that the test case runs smoothly with the initialized SVG class.
Your assistance in this matter would be greatly appreciated.