-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.setup.js
106 lines (102 loc) · 2.1 KB
/
jest.setup.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* eslint-disable no-undef */
/**
* Mock out a global mediawiki object for use in unit tests
* Adapted from:
* https://github.com/wikimedia/mw-node-qunit/blob/master/src/mockMediaWiki.js
*
* The basic Jest mock functions here can be overridden with more specific
* behavior as needed in individual test files.
*/
var mw;
// Mock API (instances created ggwith new mw.Api() )
function Api() {}
Api.prototype.get = jest.fn().mockResolvedValue( {} );
Api.prototype.post = jest.fn().mockResolvedValue( {} );
Api.prototype.getToken = jest.fn().mockResolvedValue( {} );
Api.prototype.postWithToken = jest.fn().mockResolvedValue( {} );
// Mock MW object
mw = {
Api: Api,
RegExp: {
escape: jest.fn()
},
Title: {
newFromText: jest.fn(),
makeTitle: jest.fn()
},
Uri: jest.fn(),
config: {
get: jest.fn()
},
confirmCloseWindow: jest.fn(),
hook: jest.fn().mockReturnValue( {
fire: jest.fn()
} ),
experiments: {
getBucket: jest.fn()
},
html: {
escape: function ( str ) {
return str.replace( /['"<>&]/g, function ( char ) {
switch ( char ) {
case '\'': return ''';
case '"': return '"';
case '<': return '<';
case '>': return '>';
case '&': return '&';
}
} );
}
},
jqueryMsg: {
parser: jest.fn()
},
language: {
convertNumber: jest.fn(),
getData: jest.fn().mockReturnValue( {} )
},
log: {
deprecate: jest.fn(),
warn: jest.fn()
},
message: jest.fn().mockReturnValue( {
text: jest.fn(),
parse: jest.fn()
} ),
msg: jest.fn(),
now: Date.now.bind( Date ),
template: {
get: jest.fn().mockReturnValue( {
render: jest.fn()
} )
},
user: {
tokens: {
get: jest.fn()
},
options: {
get: jest.fn()
},
isAnon: jest.fn(),
generateRandomSessionId: function () { return Math.random().toString(); }
},
trackSubscribe: jest.fn(),
track: jest.fn(),
util: {
getParamValue: jest.fn(),
getUrl: jest.fn()
},
loader: {
load: jest.fn(),
using: jest.fn(),
require: jest.fn()
},
requestIdleCallback: jest.fn(),
storage: {
get: jest.fn(),
set: jest.fn(),
remove: jest.fn()
},
notify: jest.fn()
};
global.mw = mw;