mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
34 lines
748 B
JavaScript
34 lines
748 B
JavaScript
function plugin (wdInstance, requests) {
|
|
if (typeof wdInstance.addCommand !== 'function') {
|
|
throw new Error('You can\'t use WebdriverAjaxStub with this version of WebdriverIO');
|
|
}
|
|
|
|
function stub(requests, done) {
|
|
window.XMLHttpRequest = function () {
|
|
this.open = function (method, url) {
|
|
this.method = method;
|
|
this.url = url;
|
|
};
|
|
|
|
this.send = function () {
|
|
this.status = 200;
|
|
this.readyState = 4;
|
|
const response = requests.shift() || [];
|
|
this.response = response;
|
|
this.responseText = response;
|
|
this.onreadystatechange();
|
|
};
|
|
|
|
return this;
|
|
};
|
|
|
|
done();
|
|
}
|
|
|
|
wdInstance.addCommand('setupStub', function() {
|
|
return wdInstance.executeAsync(stub, requests);
|
|
});
|
|
}
|
|
|
|
module.exports.init = plugin;
|