'How to create an automatic mock for built-in objects? (Jest, Vanilla JS)
I know that with Jest you can create an automatic class mock for an ES6 class. You can do that by calling jest.mock() with the filename as parameter, like shown below:
import ClassThatShouldBeMocked from "./path/to/the/file.js";
jest.mock("./path/to/the/file.js");
// ClassThatShouldBeMocked is now mocked
But in my case I want to mock built-in objects like HTMLElement or CanvasRenderingContext2D. How do I get the path of such built-in objects? Is there another way to achieve an automatic mock in this case?
Currently I'm using jest.spyOn() to create an spy function for each method of this class, that is called in my code. This works but takes up much more time and effort, when I have to call many functions and methods every time.
Edit:
Im currently using:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
