Skip to content

Commit a291945

Browse files
committed
fix(test): add polyfill
1 parent 676ab63 commit a291945

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

tests/unit/setup.js

+40-27
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,64 @@ const path = require('path')
22
const glob = require('glob')
33

44
global.EVENTS = [
5-
'touchstart',
6-
'touchmove',
7-
'touchcancel',
8-
'touchend',
9-
'click', //tap=>click
10-
'longpress',
11-
'longtap',
12-
'transitionend',
13-
'animationstart',
14-
'animationiteration',
15-
'animationend',
16-
'touchforcechange'
5+
'touchstart',
6+
'touchmove',
7+
'touchcancel',
8+
'touchend',
9+
'click', //tap=>click
10+
'longpress',
11+
'longtap',
12+
'transitionend',
13+
'animationstart',
14+
'animationiteration',
15+
'animationend',
16+
'touchforcechange'
1717
]
1818

1919
global.COMPONENTS = []
2020

2121
glob.sync('../../src/core/view/components/**/*/index.vue', {
22-
nodir: true,
23-
cwd: __dirname
22+
nodir: true,
23+
cwd: __dirname
2424
}).forEach(file => {
25-
global.COMPONENTS.push(path.basename(path.dirname(file)))
25+
global.COMPONENTS.push(path.basename(path.dirname(file)))
2626
})
2727

2828
glob.sync('../../src/platforms/' + process.env.UNI_PLATFORM + '/view/components/**/*/index.vue', {
29-
nodir: true,
30-
cwd: __dirname
29+
nodir: true,
30+
cwd: __dirname
3131
}).forEach(file => {
32-
global.COMPONENTS.push(path.basename(path.dirname(file)))
32+
global.COMPONENTS.push(path.basename(path.dirname(file)))
3333
})
3434

3535
let lastTime = 0
3636
global.requestAnimationFrame = function(callback, element) {
37-
const currTime = new Date().getTime()
38-
const timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
39-
const id = global.setTimeout(function() {
40-
callback(currTime + timeToCall)
41-
}, timeToCall)
42-
lastTime = currTime + timeToCall
43-
return id
37+
const currTime = new Date().getTime()
38+
const timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
39+
const id = global.setTimeout(function() {
40+
callback(currTime + timeToCall)
41+
}, timeToCall)
42+
lastTime = currTime + timeToCall
43+
return id
4444
}
4545

4646
global.cancelAnimationFrame = function(id) {
47-
clearTimeout(id)
47+
clearTimeout(id)
4848
}
4949

5050
require('jsdom-global')(undefined, {
51-
pretendToBeVisual: true
51+
pretendToBeVisual: true
5252
})
53+
//fake
54+
HTMLCanvasElement.prototype.getContext = function getContext() {
55+
return {}
56+
}
57+
window.Date = Date
58+
localStorage = {
59+
getItem: function(key) {
60+
return this[key]
61+
},
62+
setItem: function(key, value) {
63+
this[key] = value
64+
}
65+
}

0 commit comments

Comments
 (0)