Skip to content

Instantly share code, notes, and snippets.

@ferm10n
Created December 5, 2018 23:30
Show Gist options
  • Save ferm10n/65aaac6b9e7d709d868bc1b4662119dc to your computer and use it in GitHub Desktop.
Save ferm10n/65aaac6b9e7d709d868bc1b4662119dc to your computer and use it in GitHub Desktop.
/// browser code we test against, using axios
function onClick () {
const ajaxRequestPromise = axios.get('/service-call'); // make the service call
ajaxRequestPromise.then(response => { // do something with the response
doSomethingFruity(response.data);
});
}
myButton.onclick = onClick; // bind to button
/////////////////////
// if we wanted to know if the service call is made, we could inject this
const _axiosGet = axios.get; // preserve the original function
axios.get = function (url) { // monkey patch
magicallyReportCallToService(); // somehow let selenium know the call was made?
return _axiosGet.apply(null, arguments); // pass the arguments to the original function. The caller (onClick) is none the wiser :)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment