JsMockito is obviously the most reliable solution. It works for each method, it is thoroughly tested and offers some useful added functions (for example, the mentioned interaction record).
However, if you do not want to add another dependency for your project, just to use it once, you can do this work manually.
window.origWwa = window.wwa; window.wwa = function() { if (arguments[0] === 'Trefferliste Webadresse') { window.wwaFired = true; } window.origWwa.apply(this, arguments); };
... do your job ...
if (!window.wwaFired) { // do something, either throw an error or console.log("oops") }
If the script to be run is in the <script>
tag and the browser of your choice is Firefox, you can onafterscriptexecute
by any function. This is shorter, but I think you cannot make sure that the correct argument was called:
document.getElementById('script').onafterscriptexecute = function() { window.wwaFired = true; };
source share