mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 22:03:11 +02:00
raf is supported natively by JSDOM (#706)
This commit is contained in:
parent
312569a734
commit
99f945bc03
|
@ -1,6 +1,11 @@
|
|||
const { JSDOM } = require('jsdom');
|
||||
|
||||
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
|
||||
const jsdom = new JSDOM(
|
||||
'<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>',
|
||||
{
|
||||
pretendToBeVisual: true,
|
||||
},
|
||||
);
|
||||
const { window } = jsdom;
|
||||
|
||||
function copyProps(src, target) {
|
||||
|
@ -20,26 +25,6 @@ function ignoreExtensions(extensions = [], returnValue = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
function mockRAF(global) {
|
||||
let callbacksQueue = [];
|
||||
|
||||
global.setInterval(() => {
|
||||
for (let i = 0; i < callbacksQueue.length; i++) {
|
||||
if (callbacksQueue[i] !== false) {
|
||||
callbacksQueue[i].call(null);
|
||||
}
|
||||
}
|
||||
|
||||
callbacksQueue = [];
|
||||
}, 1000 / 60);
|
||||
|
||||
global.requestAnimationFrame = callback => callbacksQueue.push(callback) - 1;
|
||||
|
||||
global.cancelAnimationFrame = id => {
|
||||
callbacksQueue[id] = false;
|
||||
};
|
||||
}
|
||||
|
||||
global.window = window;
|
||||
global.document = window.document;
|
||||
global.navigator = {
|
||||
|
@ -52,9 +37,9 @@ global.Option = window.Option;
|
|||
global.HTMLOptionElement = window.HTMLOptionElement;
|
||||
global.HTMLOptGroupElement = window.HTMLOptGroupElement;
|
||||
global.DocumentFragment = window.DocumentFragment;
|
||||
global.requestAnimationFrame = window.requestAnimationFrame;
|
||||
|
||||
copyProps(window, global);
|
||||
mockRAF(global);
|
||||
|
||||
ignoreExtensions(['.scss', '.css']);
|
||||
ignoreExtensions(['.jpg', '.png', '.svg'], '');
|
||||
|
|
Loading…
Reference in a new issue