zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Define certain DOM elements
// that are not defined in the jest environment
 
const currentScript = document.createElement('script');
currentScript.src = "http://bogus";
 
Object.defineProperty(document, 'currentScript', {
  value: currentScript
});
 
// local storage mock
global.localStorage = {
    _dict: {},
    getItem: (key) => global.localStorage._dict[key],
    setItem: (key, value) => global.localStorage._dict[key] = value
}
 
// Missing XMLHttpRequest methods
XMLHttpRequest.prototype.abort = () => {};
 
// Missing canvas methods
HTMLCanvasElement.prototype.getContext = () => null;
 
// Translation methods provided by Django
global.gettext = v => v;
global.interpolate = (v, opt) => v;
global.get_format = v => v;