-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.js
98 lines (91 loc) · 2.26 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
'use strict';
const $ = require( 'jquery' );
const { config } = require( '@vue/test-utils' );
// Mock Vue plugins in test suites
config.global.mocks = {
$i18n: ( str ) => ( {
text: () => str,
parse: () => str
} )
};
config.global.directives = {
'i18n-html': ( el, binding ) => {
el.innerHTML = `${ binding.arg } (${ binding.value })`;
}
};
/* global jest:false */
function Api() {}
Api.prototype.get = jest.fn().mockReturnValue( $.Deferred().resolve().promise() );
Api.prototype.post = jest.fn().mockResolvedValue( {} );
Api.prototype.getToken = jest.fn().mockResolvedValue( {} );
Api.prototype.postWithToken = jest.fn().mockResolvedValue( {} );
Api.prototype.saveOption = jest.fn();
function Title() {}
Title.prototype.getMainText = jest.fn().mockReturnValue( '' );
Title.prototype.getName = jest.fn().mockReturnValue( '' );
Title.prototype.getNamespaceId = jest.fn().mockReturnValue( 0 );
Title.prototype.getNamespacePrefix = jest.fn().mockReturnValue( '' );
Title.newFromText = jest.fn().mockReturnValue( {
fragment: null,
namespace: 0,
title: '',
getMainText: jest.fn().mockReturnValue( 'mock' ),
getName: jest.fn().mockReturnValue( 'mock' ),
getExtension: jest.fn().mockReturnValue( 'mock' ),
getNamespaceId: jest.fn().mockReturnValue( 0 )
} );
const mw = {
Api: Api,
config: {
get: jest.fn()
},
message: jest.fn().mockReturnValue( {
text: jest.fn(),
parse: jest.fn(),
params: jest.fn( () => mw.message() )
} ),
msg: jest.fn().mockReturnValue( '' ),
Uri: jest.fn().mockReturnValue( {
getQueryString: jest.fn(),
query: {
type: ''
}
} ),
Title: Title,
util: {
parseImageUrl: jest.fn().mockReturnValue( {
resizeUrl: jest.fn()
} )
},
language: {
convertNumber: jest.fn()
},
storage: {
get: jest.fn(),
setObject: jest.fn(),
getObject: jest.fn(),
remove: jest.fn()
},
notify: jest.fn(),
OgvJsSupport: {
basePath: jest.fn(),
loadIfNeeded: jest.fn()
},
loader: {
using: jest.fn()
},
user: {
options: {
get: jest.fn().mockReturnValue( 0 ),
set: jest.fn()
},
isNamed: jest.fn().mockReturnValue( true )
}
};
/*
* MW front-end code expects certain global variables to exist in the
* environment. This sets up things like "mw" object, jquery, etc. for use
* in tests.
*/
global.mw = mw;
global.$ = require( 'jquery' );