Skip to content

Commit

Permalink
feat(XMLHttpRequest): Now this is the change for checking outstanding…
Browse files Browse the repository at this point in the history
… requests
  • Loading branch information
alfonso-presa committed Jul 27, 2016
1 parent 2fca165 commit 5546c85
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
32 changes: 16 additions & 16 deletions dist/protractor-testability-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,10 @@ return {
}
};

window.getAllAngularTestabilities = function() {
return [ window.angular.getTestability() ];
window.getAllAngularTestabilities = function () {
return [window.angular.getTestability()];
};
}
function onload() {
if (window.$) {
window.$.ajaxStart(window.testability.wait.oneMore);
window.$.ajaxStop(window.testability.wait.oneLess);
}
}

if (window.addEventListener) {
window.addEventListener('onload', onload);
}
else {
window.attachEvent('load', onload);
}

function patchFunction(set, clear, filterTime) {
var setFn = window[set];
Expand Down Expand Up @@ -121,12 +108,25 @@ return {
patchFunction('setInterval', 'clearInterval', true);
patchFunction('setImmediate', 'clearImmediate', false);

var oldOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
if(window.testability) {
testability.wait.oneMore();
this.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
testability.wait.oneLess();
}
}, false);
}
oldOpen.call(this, method, url, async, user, pass);
};

patchPromiseFunction('fetch');
});
},
waitForPromise: function () {
return browser.executeAsyncScript(
'return testability.when.ready.apply(null,arguments)')
'return window.testability && window.testability.when.ready.apply(null,arguments)')
.then(function (browserErr) {
if (browserErr) {
throw 'Error while waiting to sync with the page: ' + JSON.stringify(browserErr);
Expand Down
5 changes: 0 additions & 5 deletions dist/protractor-testability-plugin.min.js

This file was deleted.

32 changes: 16 additions & 16 deletions lib/protractor-testability-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,10 @@ return {
}
};

window.getAllAngularTestabilities = function() {
return [ window.angular.getTestability() ];
window.getAllAngularTestabilities = function () {
return [window.angular.getTestability()];
};
}
function onload() {
if (window.$) {
window.$.ajaxStart(window.testability.wait.oneMore);
window.$.ajaxStop(window.testability.wait.oneLess);
}
}

if (window.addEventListener) {
window.addEventListener('onload', onload);
}
else {
window.attachEvent('load', onload);
}

function patchFunction(set, clear, filterTime) {
var setFn = window[set];
Expand Down Expand Up @@ -101,12 +88,25 @@ return {
patchFunction('setInterval', 'clearInterval', true);
patchFunction('setImmediate', 'clearImmediate', false);

var oldOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
if(window.testability) {
testability.wait.oneMore();
this.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
testability.wait.oneLess();
}
}, false);
}
oldOpen.call(this, method, url, async, user, pass);
};

patchPromiseFunction('fetch');
});
},
waitForPromise: function () {
return browser.executeAsyncScript(
'return testability.when.ready.apply(null,arguments)')
'return window.testability && window.testability.when.ready.apply(null,arguments)')
.then(function (browserErr) {
if (browserErr) {
throw 'Error while waiting to sync with the page: ' + JSON.stringify(browserErr);
Expand Down

0 comments on commit 5546c85

Please sign in to comment.