Skip to content

Instantly share code, notes, and snippets.

@andreroggeri
Last active October 21, 2021 07:23
Show Gist options
  • Save andreroggeri/c4287ea3c67e7623364b60f2b3506945 to your computer and use it in GitHub Desktop.
Save andreroggeri/c4287ea3c67e7623364b60f2b3506945 to your computer and use it in GitHub Desktop.
Checks the Angular stability and logs on the console. Useful for debugging long protractor waits
/**
* Copy and paste the code below on your browser console
* It will log the stable changes and how long it took to become stable
*/
let currentStatus = undefined;
let root = $('app-root'); // Change this selector to the component that you'll be watching (Usually the root component)
let startTime = new Date();
let stabilityChecker = setInterval(() => {
let newStatus = window.getAngularTestability(root).isStable();
if (currentStatus !== newStatus) {
currentStatus = newStatus;
console.log(`[StabilityChecker] Stable status changed to => ${currentStatus}`);
if (currentStatus) {
let delta = (new Date() - startTime) / 1000;
console.log(`[StabilityChecker] Took ${delta} seconds`);
} else {
startTime = new Date();
}
}
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment