/ src / tests / __mocks__ / jsdom.ts
jsdom.ts
 1  /**
 2   * Mock for jsdom module
 3   *
 4   * This mock provides a minimal JSDOM implementation for tests without loading
 5   * the full jsdom library which may have ESM dependencies.
 6   */
 7  
 8  export class JSDOM {
 9    window: {
10      document: {
11        createElement: (tagName: string) => any;
12        createTextNode: (text: string) => any;
13      };
14    };
15  
16    constructor(html?: string, options?: any) {
17      // Create a minimal window object with document
18      this.window = {
19        document: {
20          createElement: (tagName: string) => {
21            return {
22              tagName: tagName.toUpperCase(),
23              children: [],
24              attributes: {},
25              appendChild: (child: any) => {},
26              setAttribute: (name: string, value: string) => {},
27              textContent: "",
28            };
29          },
30          createTextNode: (text: string) => {
31            return {
32              nodeType: 3, // TEXT_NODE
33              textContent: text,
34            };
35          },
36        },
37      };
38    }
39  
40    static fromURL(url: string, options?: any): Promise<JSDOM> {
41      return Promise.resolve(new JSDOM("", options));
42    }
43  
44    static fromFile(path: string, options?: any): Promise<JSDOM> {
45      return Promise.resolve(new JSDOM("", options));
46    }
47  }
48  
49  // Export default
50  export default { JSDOM };